From 368413bb517490d15bc9aa55551c171cfecbd917 Mon Sep 17 00:00:00 2001 From: JoYo <> Date: Tue, 14 Dec 2021 18:07:10 -0500 Subject: [PATCH] simplified parsing loop --- banana/parsing.py | 22 ++++++++++++++++++++++ banana/scripts.py | 41 +++++------------------------------------ 2 files changed, 27 insertions(+), 36 deletions(-) create mode 100644 banana/parsing.py diff --git a/banana/parsing.py b/banana/parsing.py new file mode 100644 index 0000000..41ff3a1 --- /dev/null +++ b/banana/parsing.py @@ -0,0 +1,22 @@ +import requests +import re +import logging + +esoui_prefix = re.compile("https://www.esoui.com/downloads/info[0-9]+\-") +esoui_version_html = re.compile('Version:\s+[^<]+') +esoui_version_split = re.compile('Version:\s+') + + +def esoui(url: str): + addon_name = esoui_prefix.split(url)[1] + addon_name = addon_name.split(".html")[0] + + response = requests.get(url) + version_line = esoui_version_html.search(response.text) + version = esoui_version_split.split(version_line.group(0))[1] + + esoui_dowload_uri = url.replace("info", "download") + response = requests.head(esoui_dowload_uri) + response.raise_for_status() + + return addon_name, version, esoui_dowload_uri diff --git a/banana/scripts.py b/banana/scripts.py index 893c26e..b612433 100644 --- a/banana/scripts.py +++ b/banana/scripts.py @@ -1,42 +1,9 @@ -import requests -import re import logging from pathlib import Path from argparse import ArgumentParser from . import config - - -def esoui_parse(addon_urls: list): - esoui_prefix = re.compile("https://www.esoui.com/downloads/info[0-9]+\-") - esoui_names = list() - - for url in addon_urls: - addon = esoui_prefix.split(url)[1] - addon = addon.split(".html")[0] - esoui_names.append(addon) - - logging.info(esoui_names) - - esoui_version_html = re.compile('Version:\s+[^<]+') - esoui_version_split = re.compile('Version:\s+') - esoui_versions = list() - - for url in addon_urls: - response = requests.get(url) - version_line = esoui_version_html.search(response.text) - version = esoui_version_split.split(version_line.group(0))[1] - esoui_versions.append(version) - - esoui_dowload_uris = list() - - for url in addon_urls: - esoui_dowload_uri = url.replace("info", "download") - response = requests.head(esoui_dowload_uri) - response.raise_for_status() - esoui_dowload_uris.append(esoui_dowload_uri) - - return esoui_names, esoui_versions, esoui_dowload_uris +from . import parsing def periodical_script(): @@ -83,5 +50,7 @@ def periodical_script(): logging.info(f'addons list created at "{config_path}"') addon_urls = config_current.get("addons") - esoui = esoui_parse(addon_urls) - logging.info(esoui) + + for url in addon_urls: + esoui = parsing.esoui(url) + logging.info(esoui)