From eaa3cc81facba13953278f8f99f573b40fc7ac6b Mon Sep 17 00:00:00 2001 From: "sganyunchi@163.com" <78394473+gi-b716@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:28:44 +0800 Subject: [PATCH] Auto update (2) --- _update.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 _update.py diff --git a/_update.py b/_update.py new file mode 100644 index 0000000..7ed7df8 --- /dev/null +++ b/_update.py @@ -0,0 +1,43 @@ +import requests +import zipfile +import sys +import os + +mirror = "https://autoHack.netlify.app/" + +lasted = requests.get("{0}/LASTED".format(mirror)) + +if os.path.exists("dataGenerator.py"): + import dataGenerator + metaObject = dataGenerator.Meta() + if lasted == metaObject._version: + print("autoHack is up to date.") + sys.exit(0) + if metaObject._version == "": + print("Disabled update.") + sys.exit(0) + +res = input("Check new version: {0}\nUpdate? (y/[n]): ".format(lasted)) +if res != 'y': + sys.exit(0) + +path = os.path.dirname(os.path.abspath(__file__)) +files = os.listdir(".") + +for file in files: + os.remove(file) + +lstFile = requests.get("{0}/meta/{1}.zip".format(mirror,lasted)) +with open("{0}.zip".format(lasted), "w") as zf: + zf.write(str(lstFile.content)) + +with zipfile.ZipFile("{0}.zip".format(lasted), "r") as z: + z.extractall("{0}\\".format(path)) + +os.remove("{0}.zip".format(lasted)) + +if os.path.exists(".\\requirements"): + os.chdir("requirements") + os.system("pip install -r requirements.txt") + os.chdir("..") + os.removedirs("requirements")