banana/banana/scripts.py

132 lines
4.0 KiB
Python
Raw Normal View History

2021-12-14 22:21:42 +00:00
from argparse import ArgumentParser
2021-12-15 23:06:20 +00:00
from pathlib import Path
from platform import system
2021-12-15 23:06:20 +00:00
import logging
2021-12-07 22:00:56 +00:00
2021-12-15 23:06:20 +00:00
from . import compare
2021-12-07 22:00:56 +00:00
from . import config
2021-12-14 23:07:10 +00:00
from . import parsing
2021-12-24 00:06:18 +00:00
from . import tamriel_trade_centre
2021-12-14 22:55:04 +00:00
2021-12-07 22:00:56 +00:00
def periodical_script():
2021-12-07 23:33:22 +00:00
parser = ArgumentParser(
description="Visit https://www.esoui.com/ to search for addons and their dependencies URLs. Edit addons.yaml in the ESO live path and add the URL for each addon for installation. "
)
2021-12-07 22:00:56 +00:00
parser.add_argument("-v", "--verbose", action="count", help="verbose logging")
2022-01-06 00:25:49 +00:00
parser.add_argument("-l", "--log", action="store_true")
parser.add_argument("-p", "--eso_live_path")
2021-12-07 22:00:56 +00:00
args = parser.parse_args()
if args.eso_live_path:
args.eso_live_path = Path(args.eso_live_path)
else:
if system() == "Windows":
args.eso_live_path = Path.home().joinpath(
"Documents\Elder Scrolls Online\live"
)
else:
args.eso_live_path = Path.home().joinpath(
".steam/steam/steamapps/compatdata/306130/pfx/drive_c/users/steamuser/Documents/Elder Scrolls Online/live/"
)
2021-12-07 22:00:56 +00:00
if args.verbose:
2022-01-06 00:24:26 +00:00
level = logging.DEBUG
format = "%(asctime)s %(filename)s:%(lineno)d %(message)s"
else:
level = logging.INFO
2022-01-06 00:27:31 +00:00
format = "%(asctime)s %(message)s"
2022-01-06 00:24:26 +00:00
if args.log:
2021-12-07 22:00:56 +00:00
logging.basicConfig(
2022-01-06 00:24:26 +00:00
level=level,
format=format,
filename=args.eso_live_path.joinpath("banana.log"),
2021-12-07 22:00:56 +00:00
)
else:
logging.basicConfig(
2022-01-06 00:24:26 +00:00
level=level,
format=format,
2021-12-07 22:00:56 +00:00
)
logging.info(args)
2021-12-07 23:33:22 +00:00
config_path = Path(args.eso_live_path).joinpath("addons.yaml")
2021-12-07 22:00:56 +00:00
config_path.touch(exist_ok=True)
config_current = config.load(config_path)
try:
config.valid(config_current)
2021-12-14 22:21:42 +00:00
except (AssertionError, AttributeError):
2021-12-07 22:00:56 +00:00
config.new(config_path)
config_current = config.load(config_path)
2021-12-07 23:33:22 +00:00
logging.info(f'addons list created at "{config_path}"')
2021-12-14 22:21:42 +00:00
live_path = args.eso_live_path.joinpath("AddOns")
2021-12-15 00:01:38 +00:00
if not live_path.is_dir():
logging.error(f"eso_live_path_invalid_dir {live_path}")
return
2021-12-15 23:06:20 +00:00
addon_urls = config_current.get("addons")
esoui_uris = list()
for url in addon_urls:
esoui = parsing.esoui(url)
esoui_uris.append(esoui)
2021-12-15 00:01:38 +00:00
for child in live_path.iterdir():
2021-12-15 23:06:20 +00:00
compare.live_to_esoui(path=child, esoui_uris=esoui_uris)
2021-12-22 23:11:29 +00:00
compare.esoui_to_live(esoui_uris=esoui_uris, live_path=live_path)
2021-12-24 00:06:18 +00:00
tamriel_trade_centre.update(live_path=live_path)
2022-01-05 20:40:58 +00:00
def ttc():
parser = ArgumentParser(description="Tamriel Trade Centre price table updater.")
2022-01-05 20:40:58 +00:00
parser.add_argument("-v", "--verbose", action="count", help="verbose logging")
2022-01-06 00:25:49 +00:00
parser.add_argument("-l", "--log", action="store_true")
parser.add_argument("-p", "--eso_live_path")
2022-01-05 20:40:58 +00:00
args = parser.parse_args()
if args.eso_live_path:
args.eso_live_path = Path(args.eso_live_path)
else:
if system() == "Windows":
args.eso_live_path = Path.home().joinpath(
"Documents\Elder Scrolls Online\live"
)
else:
args.eso_live_path = Path.home().joinpath(
".steam/steam/steamapps/compatdata/306130/pfx/drive_c/users/steamuser/Documents/Elder Scrolls Online/live/"
)
2022-01-05 20:40:58 +00:00
if args.verbose:
2022-01-06 00:24:26 +00:00
level = logging.DEBUG
format = "%(asctime)s %(filename)s:%(lineno)d %(message)s"
else:
level = logging.INFO
2022-01-06 00:27:31 +00:00
format = "%(asctime)s %(message)s"
2022-01-06 00:24:26 +00:00
if args.log:
2022-01-05 20:40:58 +00:00
logging.basicConfig(
2022-01-06 00:24:26 +00:00
level=level,
format=format,
filename=args.eso_live_path.joinpath("banana.log"),
2022-01-05 20:40:58 +00:00
)
else:
logging.basicConfig(
2022-01-06 00:24:26 +00:00
level=level,
format=format,
2022-01-05 20:40:58 +00:00
)
logging.info(args)
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
tamriel_trade_centre.update(live_path=live_path)