From ca4218fae0e83047653ff20edcdf5b792776bd0d Mon Sep 17 00:00:00 2001 From: klensy Date: Wed, 5 Aug 2020 20:21:11 +0300 Subject: [PATCH] update_checker: check game version online and download yup file --- requirements.txt | 3 +++ setup.py | 12 ++++++--- src/wt_tools/update_checker.py | 48 ++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 src/wt_tools/update_checker.py diff --git a/requirements.txt b/requirements.txt index bf5c307..17b7d2d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,3 +22,6 @@ bencode.py==4.0.0 # for diffing jsons jsondiff==1.2.0 + +# for http requests +requests==2.24.0 diff --git a/setup.py b/setup.py index 17d6e13..74c6b30 100644 --- a/setup.py +++ b/setup.py @@ -6,11 +6,11 @@ src_path = "src/wt_tools/" packages = [] includes = [] -excludes = ["socket", "unittest", "http", "email", "pydoc", "construct.examples", "bz2"] +excludes = ["unittest", "pydoc", "construct.examples", "bz2"] includefiles = [os.path.join(src_path, "./formats/blk.lark"), os.path.join(src_path, '../../README.md')] zip_include_packages = ["collections", "construct", "ctypes", "encodings", "json", "logging", "importlib", "formats", "zstandard", "xml", "urllib", "distutils", "click", "pkg_resources", "colorama", "bencodepy", - "jsondiff"] + "jsondiff", "requests", "chardet", "idna", "urllib3", "email", "http"] blk_unpack = Executable( @@ -45,9 +45,13 @@ script=os.path.join(src_path, "update_differ.py"), ) +update_checker = Executable( + script=os.path.join(src_path, "update_checker.py"), +) + setup( name="wt_tools", - version="0.2.2.6-dev", + version="0.2.2.7-dev", author='klensy', description="War Thunder resource extraction tools", url="https://github.com/klensy/wt-tools", @@ -55,5 +59,5 @@ "packages": packages, "zip_include_packages": zip_include_packages, "path": sys.path + [src_path]}}, executables=[blk_unpack, clog_unpack, ddsx_unpack, dxp_unpack, vromfs_unpacker, wrpl_unpacker, blk_minify, - update_differ] + update_differ, update_checker] ) diff --git a/src/wt_tools/update_checker.py b/src/wt_tools/update_checker.py new file mode 100644 index 0000000..0de0114 --- /dev/null +++ b/src/wt_tools/update_checker.py @@ -0,0 +1,48 @@ +from urllib.parse import urlparse + +import click +import requests + + +def check_versions_online(): + """check""" + tag_list = ["", "dev", "dev-stable", "production-rc", "test", "nightly", "tournament", "experimental", + "ps4submission", "xbox-submission", "experimental2", "china-test", "china-dev"] + headers = {"User-Agent": "wt-tools"} + versions_url = "https://yupmaster.gaijinent.com/yuitem/get_version.php?proj=warthunder&tag={}" + + s = requests.Session() + s.headers.update(headers) + for tag in tag_list: + r = s.get(versions_url.format(tag)) + # if any valid version + if r.text != "NOITEM": + print(tag if tag else "default", r.text) + + +def download_yup(tag): + headers = {"User-Agent": "wt-tools"} + yup_url = "https://yupmaster.gaijinent.com/yuitem/get_version_yup.php?proj=warthunder&tag={}" + r = requests.get(yup_url.format("" if tag == "default" else tag), headers=headers) + for line in r.text.split(): + # get the first good link + if line.startswith("https"): + name = urlparse(line).path.strip('/') + r = requests.get(line, headers=headers) + with open("{}.{}".format(tag, name), 'wb') as f: + f.write(r.content) + break + + +@click.command() +@click.option('--check_versions', is_flag=True, default=False) +@click.option('--download_yup', "tag") +def main(check_versions, tag): + if check_versions: + check_versions_online() + elif tag: + download_yup(tag) + + +if __name__ == '__main__': + main()