update live addons
							parent
							
								
									a5daac007d
								
							
						
					
					
						commit
						21bbc6c6b2
					
				|  | @ -1,27 +0,0 @@ | |||
| { | ||||
|     // See https://go.microsoft.com/fwlink/?LinkId=733558 | ||||
|     // for the documentation about the tasks.json format | ||||
|     "version": "2.0.0", | ||||
|     "tasks": [ | ||||
|         { | ||||
|             "label": "build", | ||||
|             "type": "shell", | ||||
|             "command": "docker-compose build", | ||||
|             "problemMatcher": [], | ||||
|             "group": { | ||||
|                 "kind": "build", | ||||
|                 "isDefault": true | ||||
|             } | ||||
|         }, | ||||
|         { | ||||
|             "label": "test", | ||||
|             "type": "shell", | ||||
|             "command": "docker-compose up", | ||||
|             "problemMatcher": [], | ||||
|             "group": { | ||||
|                 "kind": "test", | ||||
|                 "isDefault": true | ||||
|             } | ||||
|         }, | ||||
|     ] | ||||
| } | ||||
|  | @ -2,6 +2,7 @@ FROM ubuntu:20.04 | |||
| ENV DEBIAN_FRONTEND noninteractive | ||||
| 
 | ||||
| RUN apt-get update && apt-get install -y \ | ||||
|     python3-packaging \ | ||||
|     python3-pip \ | ||||
|     python3-requests \ | ||||
|     python3-yaml \ | ||||
|  |  | |||
|  | @ -0,0 +1,50 @@ | |||
| from io import BytesIO | ||||
| from pathlib import Path | ||||
| from shutil import rmtree, copytree | ||||
| from tempfile import TemporaryDirectory | ||||
| from zipfile import ZipFile | ||||
| import logging | ||||
| import requests | ||||
| 
 | ||||
| from . import parsing | ||||
| 
 | ||||
| 
 | ||||
| def live_to_esoui(*, path: Path, esoui_uris: list): | ||||
|     live_name, live_version, live_path = parsing.live(path) | ||||
| 
 | ||||
|     if not live_path: | ||||
|         return | ||||
| 
 | ||||
|     esoui_name, esoui_version, esoui_uri = None, None, None | ||||
| 
 | ||||
|     for name, version, uri in esoui_uris: | ||||
|         if name in live_name: | ||||
|             esoui_name, esoui_version, esoui_uri = name, version, uri | ||||
|             break | ||||
| 
 | ||||
|     if not esoui_name: | ||||
|         rmtree(live_path) | ||||
|         logging.info(f"{live_name} addon removed from: {live_path}") | ||||
|         return | ||||
| 
 | ||||
|     if esoui_version == live_version: | ||||
|         logging.info(f"{live_name} is already up to date.") | ||||
|         return | ||||
| 
 | ||||
|     response = requests.get(esoui_uri) | ||||
|     response.raise_for_status() | ||||
| 
 | ||||
|     temp_dir = TemporaryDirectory() | ||||
|     temp_path = Path(temp_dir.name) | ||||
| 
 | ||||
|     zip_file = ZipFile(BytesIO(response.content)) | ||||
|     zip_file.extractall(temp_path) | ||||
| 
 | ||||
|     rmtree(live_path) | ||||
| 
 | ||||
|     for each in temp_path.iterdir(): | ||||
|         copytree(each, live_path) | ||||
| 
 | ||||
|     logging.info( | ||||
|         f"{live_name} updated from {live_version} to {esoui_version} at {live_path}" | ||||
|     ) | ||||
|  | @ -6,6 +6,7 @@ import requests | |||
| esoui_prefix = re.compile("https://www.esoui.com/downloads/info[0-9]+\-") | ||||
| esoui_version_html = re.compile('<div\s+id="version">Version:\s+[^<]+') | ||||
| esoui_version_split = re.compile('<div\s+id="version">Version:\s+') | ||||
| esoui_download = re.compile('https://cdn.esoui.com/downloads/file[^"]*') | ||||
| live_title = re.compile("##\s+Title:\s+.*") | ||||
| live_title_split = re.compile("##\s+Title:\s+") | ||||
| live_version = re.compile("##\s+Version:\s+.*") | ||||
|  | @ -17,24 +18,38 @@ def esoui(url: str): | |||
|     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] | ||||
|     response.raise_for_status() | ||||
| 
 | ||||
|     esoui_dowload_uri = url.replace("info", "download") | ||||
|     version_line = esoui_version_html.search(response.text).group(0) | ||||
|     version = esoui_version_split.split(version_line)[1] | ||||
| 
 | ||||
|     esoui_page_url = url.replace("info", "download").replace(".html", "") | ||||
| 
 | ||||
|     response = requests.get(esoui_page_url) | ||||
|     response.raise_for_status() | ||||
| 
 | ||||
|     esoui_dowload_uri = esoui_download.search(response.text).group(0) | ||||
|     response = requests.head(esoui_dowload_uri) | ||||
|     response.raise_for_status() | ||||
| 
 | ||||
|     return addon_name, version, esoui_dowload_uri | ||||
| 
 | ||||
| 
 | ||||
| def live_addon(path: Path): | ||||
| def live(path: Path): | ||||
|     for meta in path.glob("*.txt"): | ||||
|         with meta.open("r") as file_open: | ||||
|             meta_data = file_open.read() | ||||
| 
 | ||||
|         title = live_title.search(meta_data) | ||||
|         title = live_title_split.split(title.group(0))[1] | ||||
|         version = live_version.search(meta_data) | ||||
|         version = live_version_split.split(version.group(0))[1] | ||||
|         try: | ||||
|             with meta.open("r") as file_open: | ||||
|                 meta_data = file_open.read() | ||||
|         except UnicodeDecodeError: | ||||
|             with meta.open("r", encoding="latin-1") as file_open: | ||||
|                 meta_data = file_open.read() | ||||
| 
 | ||||
|     return title, version | ||||
|         addon_name = live_title.search(meta_data).group(0) | ||||
|         addon_name = live_title_split.split(addon_name)[1] | ||||
|         version = live_version.search(meta_data).group(0) | ||||
|         version = live_version_split.split(version)[1] | ||||
| 
 | ||||
|         return addon_name, version, path | ||||
| 
 | ||||
|     return None, None, None | ||||
|  |  | |||
|  | @ -1,7 +1,8 @@ | |||
| import logging | ||||
| from pathlib import Path | ||||
| from argparse import ArgumentParser | ||||
| from pathlib import Path | ||||
| import logging | ||||
| 
 | ||||
| from . import compare | ||||
| from . import config | ||||
| from . import parsing | ||||
| 
 | ||||
|  | @ -49,18 +50,18 @@ def periodical_script(): | |||
|         config_current = config.load(config_path) | ||||
|         logging.info(f'addons list created at "{config_path}"') | ||||
| 
 | ||||
|     addon_urls = config_current.get("addons") | ||||
| 
 | ||||
|     for url in addon_urls: | ||||
|         esoui = parsing.esoui(url) | ||||
|         logging.info(esoui) | ||||
| 
 | ||||
|     live_path = Path(args.eso_live_path).joinpath("AddOns") | ||||
| 
 | ||||
|     if not live_path.is_dir(): | ||||
|         logging.error(f"eso_live_path_invalid_dir {live_path}") | ||||
|         return | ||||
| 
 | ||||
|     addon_urls = config_current.get("addons") | ||||
|     esoui_uris = list() | ||||
| 
 | ||||
|     for url in addon_urls: | ||||
|         esoui = parsing.esoui(url) | ||||
|         esoui_uris.append(esoui) | ||||
| 
 | ||||
|     for child in live_path.iterdir(): | ||||
|         live_addon = parsing.live_addon(child) | ||||
|         logging.info(live_addon) | ||||
|         compare.live_to_esoui(path=child, esoui_uris=esoui_uris) | ||||
|  |  | |||
|  | @ -16,5 +16,6 @@ include = "banana" | |||
| eso-banana-script = "banana:scripts.periodical_script" | ||||
| 
 | ||||
| [tool.poetry.dependencies] | ||||
| requests = "" | ||||
| packaging = "" | ||||
| PyYAML = "" | ||||
| requests = "" | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 JoYo
						JoYo