forked from QuarkSources/quarksources.github.io
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAltSourcerer.py
188 lines (148 loc) · 8.24 KB
/
AltSourcerer.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
187
188
import json
import datetime
import re
print('\n' + '--------------------------' + '\n')
source_action = input('\033[1;96mWhat source would you like to use:\033[0m' + "\n" + "\n" + '(\033[1;96m1\033[0m) wuxu-complete++' + "\n" '(\033[1;96m2\033[0m) wuxu-complete' + "\n" + '(\033[1;96m3\033[0m) other' + "\n" + "\n" + '\033[1;96mEnter 1, 2 or 3: ' + '\033[0m').lower()
if source_action == '1':
userfile = 'wuxu-complete++.json'
elif source_action == '2':
userfile = 'wuxu-complete.json'
elif source_action == '3':
userfile = input('\033[1;96m' + 'Please enter the name of your JSON or the path following the name (include .json): ' + '\033[0m')
# Load the JSON data from a file
with open(userfile, 'r') as f:
data = json.load(f)
print('\n' + '--------------------------' + '\n')
app_action = input('\033[1;96m' + 'Do you want to:' + '\033[0m' + "\n" + "\n" + '(\033[1;96m1\033[0m) Update an existing app' + "\n" '(\033[1;96m2\033[0m) Add a new app' + "\n" + "\n" + '\033[1;96mEnter 1 or 2 : ' + '\033[0m').lower()
if app_action == '1':
# Display a numbered list of app names for the user to choose from
print('\n' + '--------------------------' + '\n')
print('\033[1;96mHere are your apps:\033[0m')
print("\n")
for i, app in enumerate(data['apps']):
print(f"(\033[1;96m{i+1}\033[0m) \033[1m{app['name']}\033[0m")
print('\n' + '--------------------------' + '\n')
# Get the app number from the user
while True:
app_num = input('\033[1;96mPlease select an app to update: \033[0m')
try:
app_num = int(app_num)
if app_num < 1 or app_num > len(data['apps']):
raise ValueError
break
except ValueError:
print('\033[1;91mError: Invalid app number\033[0m')
# Get the selected app
selected_app = data['apps'][app_num - 1]
# Display the previous version data
print("\n")
print(f"\033[1mPrevious Version Data for {selected_app['name']}:\033[0m")
print("\n")
for i, version in enumerate(selected_app['versions']):
print(f"\n\033[1mVersion {i+1}:\033[0m")
print("\n")
print(f"\033[1;96mDate:\033[0m {version['date']}")
print(f"\033[1;96mVersion Number:\033[0m {version['version']}")
print(f"\033[1;96mDownload URL:\033[0m {version['downloadURL']}")
print(f"\033[1;96mChangelog:\033[0m {version['localizedDescription']}")
print(f"\033[1;96mSize (in bytes):\033[0m {version['size']}")
print("\n")
# Get the version data from the user
while True:
print("\n")
version_date = input('\033[1;96mNew version date (YYYY-MM-DD): \033[0m')
try:
new_date = datetime.datetime.strptime(version_date, '%Y-%m-%d')
old_date = datetime.datetime.strptime(selected_app['versions'][0]['date'], '%Y-%m-%d')
if new_date > old_date:
new_version_num = input('\033[1;96mNew version: \033[0m')
old_version_num = selected_app['versions'][0]['version']
if new_version_num > old_version_num:
break
else:
print('\033[1;91mError: The updated version must be greater than the existing version.\033[0m')
else:
print('\033[1;91mError: The updated version date must be greater than the existing version date.\033[0m')
except ValueError:
print('\033[1;91mError: Date must be in the format YYYY-MM-DD\033[0m')
new_size = input('\033[1;96mNew size in bytes (leave blank if not changed): \033[0m')
if new_size == '':
new_size = selected_app['versions'][0]['size']
else:
new_size = int(new_size)
new_version = {
'date': version_date,
'downloadURL': input('\033[1;96mNew download URL: \033[0m'),
'localizedDescription': input('\033[1;96mNew changelog: \033[0m'),
'size': new_size,
'version': new_version_num
}
# Add the new version to the beginning of the versions list
selected_app['versions'].insert(0, new_version)
# Update the app data with the new version information
selected_app['versionDate'] = new_version['date']
selected_app['downloadURL'] = new_version['downloadURL']
selected_app['versionDescription'] = new_version['localizedDescription']
selected_app['size'] = new_version['size']
selected_app['version'] = new_version['version']
# Find the news with the matching bundle identifier and update its date
for news in data['news']:
if news['appID'] == selected_app['bundleIdentifier']:
news['date'] = new_version['date']
break
# Save the updated JSON data
with open(userfile, 'w') as f:
json.dump(data, f, indent=2)
print('\n' + '\033[1;92m' + 'Success! ' + '\033[0m' + '\033[1m' + selected_app['name'] + '\033[0m' + ' has been updated from ' + '\033[1m' + old_version_num + ' to ' + new_version_num + '!' + '\033[0m' '\n')
exit()
elif app_action == '2':
# Define a regular expression pattern for the date format (YYYY-MM-DD)
date_pattern = r'^\d{4}-\d{2}-\d{2}$'
print('\n' + '--------------------------' + '\n')
# Get user input for new app
new_app = {}
new_app['bundleIdentifier'] = input('\033[1;96m' + 'Enter the bundle identifier of the new app: ' + '\033[0m')
new_app['developerName'] = input('\033[1;96m' + 'Enter the developer name of the new app: ' + '\033[0m')
new_app['downloadURL'] = input('\033[1;96m' + 'Enter the download URL of the new app: ' + '\033[0m')
new_app['iconURL'] = input('\033[1;96m' + 'Enter the icon URL of the new app: ' + '\033[0m')
new_app['localizedDescription'] = input('\033[1;96m' + 'Enter the description of the new app: ' + '\033[0m')
new_app['name'] = input('\033[1;96m' + 'Enter the name of the new app: ' + '\033[0m')
new_app['screenshotURLs'] = input('\033[1;96m' + 'Enter a list of screenshot URLs of the new app (separated by commas): ' + '\033[0m').split(',')
new_app['size'] = int(input('\033[1;96m' + 'Enter the size of the new app: ' + '\033[0m'))
new_app['subtitle'] = input('\033[1;96m' + 'Enter the subtitle of the new app: ' + '\033[0m')
new_app['tintColor'] = input('\033[1;96m' + 'Enter the hex tint color of the new app: ' + '\033[0m').strip()
if not new_app['tintColor'].startswith('#'):
new_app['tintColor'] = '#' + new_app['tintColor']
new_app['version'] = input('\033[1;96m' + 'Enter the version of the new app: ' + '\033[0m')
new_app['versionDate'] = input('\033[1;96m' + 'Enter the version date of the new app (YYYY-MM-DD): ' + '\033[0m')
while not re.match(date_pattern, new_app['versionDate']):
new_app['versionDate'] = input('\033[1;91m' + 'Invalid date format. Please enter the version date of the new app (YYYY-MM-DD): ' + '\033[0m')
new_app['versionDescription'] = input('\033[1;96m' + 'Enter the changelog: ' + '\033[0m')
new_app['versions'] = []
data['apps'].insert(0, new_app)
# Get user input for new app version
new_app_version = {}
new_app_version['date'] = new_app['versionDate']
new_app_version['downloadURL'] = new_app['downloadURL']
new_app_version['localizedDescription'] = new_app['versionDescription']
new_app_version['size'] = new_app['size']
new_app_version['version'] = new_app['version']
new_app['versions'].insert(0, new_app_version)
# Get user input for new news
new_news = {}
new_news['appID'] = new_app['bundleIdentifier']
new_news['caption'] = '\033[1;96m' + new_app['name'] + ' has been added to the source! Click here for more info\033[0m'
new_news['date'] = new_app['versionDate']
new_news['identifier'] = input('\033[1;96mEnter news identifier (appname-added): \033[0m')
new_news['imageURL'] = input('\033[1;96mEnter the news image URL: \033[0m')
new_news['notify'] = 'true'
new_news['tintColor'] = new_app['tintColor']
new_news['title'] = new_app['name'] + 'Added!'
data['news'].insert(0, new_news)
# Save the JSON file
with open(userfile, 'w') as f:
json.dump(data, f, indent=4)
else:
print('Invalid input. Please enter either "update" or "add".')
print('\n' + '\033[1;92m' + 'Success! ' + '\033[0m' + '\033[1m' + new_app['name'] + '\033[0m' + ' has been added to ' + '\033[1m' + userfile + '!' + '\033[0m' '\n')
exit()