-
Notifications
You must be signed in to change notification settings - Fork 0
/
_update.py
70 lines (56 loc) · 1.83 KB
/
_update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import requests
import zipfile
import sys
import os
mirrorList = ["https://autohack.netlify.app/", "https://gi-b716.github.io/autoHack/", "https://autohack.pages.dev/"]
pingTime = []
if os.path.exists("dataGenerator.py"):
import dataGenerator
metaObject = dataGenerator.Meta()
if metaObject._version == "":
print("Disabled update.")
sys.exit(0)
lasted = None
for mirror in mirrorList:
res = None
try:
res = requests.get("{0}/LASTED".format(mirror), timeout=5)
lasted = str(res.content, "utf-8")
except:
pingTime.append(1000000.0)
print("> \"{0}\": Time Out! <".format(mirror), file=sys.stderr)
else:
pingTime.append(res.elapsed.total_seconds())
print("> \"{0}\": {1}s <".format(mirror, res.elapsed.total_seconds()), file=sys.stderr)
if lasted == None:
print("Check your network connection!")
sys.exit(-1)
if os.path.exists("dataGenerator.py"):
import dataGenerator
metaObject = dataGenerator.Meta()
if lasted == metaObject._version:
print("autoHack is up to date.")
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(".")
mirror = mirrorList[pingTime.index(min(pingTime))]
print("> Mirror: \"{0}\" <".format(mirror), file=sys.stderr)
lstFile = requests.get("{0}/meta/{1}.zip".format(mirror,lasted))
with open("{0}.zip".format(lasted), "wb") as zf:
zf.write(lstFile.content)
for file in files:
if os.path.isdir(file):
os.system("rmdir /s/q {0}".format(file))
else:
os.system("del {0}".format(file))
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.system("rmdir /s/q requirements")