-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathall.py
186 lines (149 loc) · 4.61 KB
/
all.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import argparse
import os
import re
import shutil
import subprocess
import sys
import time
import requests
delay = 3
def version():
url = "https://api.github.com/repos/HerrErde/subway-source/releases/latest"
response = requests.get(url)
data = response.json()
return data.get("tag_name", "")
def get_rm(nodownload):
rm_dir = ["temp/input"]
if not nodownload:
tmp_dir = "temp/data"
rm_dir.insert(0, tmp_dir)
return rm_dir
def setup():
os.makedirs("temp", exist_ok=True)
os.makedirs("temp/data", exist_ok=True)
os.makedirs("temp/input", exist_ok=True)
def get_scripts(version, onlydownload, nodownload):
if onlydownload:
return [
[
f"script/setup.py",
version,
]
]
script_list = [
["script/generate_characters.py"],
["script/generate_boards.py"],
["script/playerprofile.py"],
["script/userstats.py"],
["script/collection.py"],
["script/challenges.py"],
["script/calender.py"],
["script/achievements.py"],
["script/quests.py"],
["script/chainoffers.py"],
["script/ui_seen.py"],
["script/update.py"],
["script/convert.py"],
["script/zip.py"],
]
if not nodownload:
download_script = [
f"script/setup.py",
version,
]
script_list.insert(0, download_script)
return script_list
def cleanup(cleanup, nodownload, nocleanup):
if nocleanup:
return
print("Starting cleanup")
rm_dir = get_rm(nodownload)
try:
for directory in rm_dir:
if os.path.exists(directory):
shutil.rmtree(directory)
print("Finished cleanup")
if cleanup:
sys.exit(1)
except KeyboardInterrupt:
print("Cleanup interrupted by user.")
sys.exit(1)
except Exception as e:
print(f"An error occurred during cleanup: {e}")
sys.exit(1)
def run_scripts(version, onlydownload, nodownload, delay):
scripts = get_scripts(version, onlydownload, nodownload)
try:
print(f"Choosing version: {version}\n")
for index, script in enumerate(scripts):
print(f"Running {script[0]}...")
subprocess.run(["python"] + script, check=True)
print(f"Finished running {script[0]}.")
# Sleep only if this is not the last script
if index < len(scripts) - 1:
time.sleep(delay)
print("\n")
except Exception as e:
print(f"Error occurred while running script: {e}")
sys.exit(1)
except KeyboardInterrupt:
print("Script execution interrupted by user.")
sys.exit(0)
def main():
parser = argparse.ArgumentParser(description="Run Subway Surfers scripts.")
parser.add_argument(
"-v", "--version", type=str, default=None, help="Choose a specific version"
)
parser.add_argument(
"-c", "--cleanup", action="store_true", help="Run cleanup function only"
)
parser.add_argument(
"-nc", "--nocleanup", action="store_true", help="Prevents cleaning up any files"
)
parser.add_argument(
"-ndl",
"--nodownload",
action="store_true",
help="Run scripts without downloading the source files (requires pre-downloaded files)",
)
parser.add_argument(
"-odl",
"--onlydownload",
action="store_true",
help="Only downloads the source files",
)
parser.add_argument(
"-dly",
"--delay",
type=int,
default=5,
help="Change the delay between the running scripts",
)
args = parser.parse_args()
# If version is not provided, set it using the version() function
if args.version is None:
args.version = version()
# Regex pattern
version_pattern = r"^\d{1,2}-\d{1,2}-\d{1,2}$"
# Validate 'version'
if args.version and not re.match(version_pattern, args.version):
print(
"Error: 'version' has the wrong format. Please use the format 'X-Y-Z' (e.g., '3-12-2')."
)
sys.exit(1)
try:
cleanup(args.cleanup, args.nodownload, args.nocleanup)
setup()
run_scripts(args.version, args.onlydownload, args.nodownload, args.delay)
except Exception as e:
print("Error:", e)
sys.exit(1)
except KeyboardInterrupt:
print("Script terminated by user.")
sys.exit(1)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("Script terminated by user.")
sys.exit(1)