-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyPlaceRoulette.py
More file actions
475 lines (284 loc) · 12 KB
/
PyPlaceRoulette.py
File metadata and controls
475 lines (284 loc) · 12 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
#!/usr/bin/env python3
import os
import sys
import io
import random
import webbrowser
import cfg
myRobloSecurityKey = cfg.settings["SecurityKey"]
#print(cfg.settings["SkipStarterPlaces"])
#print(cfg.settings["SkipR15Only"])
settings = {
"SkipStarterPlaces": cfg.settings["SkipStarterPlaces"],
"SkipPrivatePlaces": cfg.settings["SkipPrivatePlaces"],
"ViewPlaceInWebBrowser": cfg.settings["ViewPlaceInWebBrowser"],
"ShowOnlySuccessfulPlaces": cfg.settings["ShowOnlySuccessfulPlaces"],
}
reqVars = {
"attempts": 0,
"searchMode": 0
}
sys.path.append("../include")
import requests
def requestUniverseID(placeID):
print("Requesting Universe ID for " + str(placeID))
uid = requests.get("https://apis.roblox.com/universes/v1/places/" + str(placeID) + "/universe")
if uid.status_code == 200:
return uid
else:
return None
def search():
searchFailed = False
placeID = createPlaceID()
session = requests.Session()
cookies = {'.ROBLOSECURITY': myRobloSecurityKey}
print("Connecting to Universes API...")
getUniverseID = requestUniverseID(placeID)
if getUniverseID == None:
searchFailed = True
else:
getUniverseID = getUniverseID.json()
universeID = getUniverseID["universeId"]
if universeID == None:
print("\nItem for ID is not a place.") # No universe ID = not a place.
searchFailed = True
if not searchFailed:
print("Connecting to Games API...")
params = {'universeIds': universeID}
getPlaceInfo = requests.get("https://games.roblox.com/v1/games", params=params, cookies=cookies)
if (getPlaceInfo.status_code != 200):
searchFailed = True
print("\nError " + str(getPlaceInfo.status_code))
else:
if not searchFailed:
pInfo = getPlaceInfo.json()
if len(pInfo) != 0:
placeName = pInfo["data"][0]["name"]
if settings["SkipStarterPlaces"]:
if placeName.endswith("'s Place"):
print("Skipping starter places...")
searchFailed = True
if settings["ShowOnlySuccessfulPlaces"]:
print("Searching for places that were popular...")
placeVisits = pInfo["data"][0]["visits"]
#print("Visits: " + str(placeVisits))
if int(placeVisits) < 15000:
searchFailed = True,
if settings["SkipPrivatePlaces"]:
print("Checking place availability...")
placeStatusParams = {'universeIds': universeID}
getPlaceStatus = requests.get("https://games.roblox.com/v1/games/multiget-playability-status", params=placeStatusParams, cookies=cookies)
if getPlaceStatus.status_code == 200:
placeStatus = getPlaceStatus.json()
isPlayable = placeStatus[0]["playabilityStatus"]
print(str(universeID) + " -> " + placeStatus[0]["playabilityStatus"])
if isPlayable != "Playable":
searchFailed = True
else:
searchFailed = True
if not searchFailed:
place = {
"name": pInfo["data"][0]["name"],
"desc": pInfo["data"][0]["description"],
"creator": pInfo["data"][0]["creator"]["name"],
"visits": pInfo["data"][0]["visits"],
"id": str(pInfo["data"][0]["rootPlaceId"]),
"created": pInfo["data"][0]["created"],
"url": '\033[94m' + "https://www.roblox.com/games/" + str(pInfo["data"][0]["rootPlaceId"]) + '\033[0;0m',
}
basicDetails = [
pInfo["data"][0]["rootPlaceId"],
pInfo["data"][0]["name"],
pInfo["data"][0]["creator"]["name"]
]
storeBasicPlaceDetails(basicDetails[0], basicDetails[1], basicDetails[2])
print("\n" + '\033[1m' + place["name"] + "\033[0;0m" + " [ " + place["url"] + " ] " )
print("Created by: " + place["creator"] + " | " + place["created"][0:10])
else:
print("\nNo data found.")
searchFailed = True
if settings["ViewPlaceInWebBrowser"]:
if not searchFailed:
viewPlaceInWebBrowser(placeID)
return searchFailed
loadBarProperties = {
"pos": 0,
"width": 3,
}
def loadingbar():
# awesome loading bar thingy I made
outer = "▫"
inner = "▪"
toDraw = "none"
if loadBarProperties["pos"] < loadBarProperties["width"]:
loadBarProperties["pos"] += 1
else:
loadBarProperties["pos"] = 0
for i in range(loadBarProperties["width"]):
if i != loadBarProperties["pos"]:
print(outer, end =" ")
else:
print(inner, end =" ")
print("\n")
def addToFavs():
basicPlaceInfo = getBasicPlaceDetails()
favs = open("favs.txt", 'a') # a for append
favs.write("\n{0},{1},{2}".format(basicPlaceInfo["id"], basicPlaceInfo["placeName"], basicPlaceInfo["creator"]))
favs.close()
basicPlaceDetails = {
"placeName": "Crossroads",
"creator": "Roblox",
"id": "0",
}
def storeBasicPlaceDetails(PlaceID, PlaceName, Creator):
# place title and ID leaves paranthesis and quotation marks for some reason. Let's clean them out.
#placeID_clean = PlaceID.split("'")
#placeName_clean = PlaceName.split('"')
basicPlaceDetails["id"] = PlaceID,
basicPlaceDetails["placeName"] = PlaceName,
basicPlaceDetails["creator"] = Creator
#print(str(basicPlaceDetails["id"]) + ", " + str(basicPlaceDetails["placeName"]) + ", " + str(basicPlaceDetails["creator"]))
def getBasicPlaceDetails():
return basicPlaceDetails
def viewPlaceInWebBrowser(pID):
webbrowser.open("https://www.roblox.com/games/" + str(pID))
def createPlaceID():
print("\nCreating a random ID...")
placeID = random.randint(cfg.settings["minID"], random.randint(cfg.settings["minID"], cfg.settings["maxID"]))
print("[OK]")
return placeID
def performSearch():
searchFailed = None
if reqVars["searchMode"] == 1:
searchFailed = search()
elif reqVars["searchMode"] == 2:
searchFailed = fastSearch()
if searchFailed:
clearScreen()
title()
loadingbar()
print("Retries: " + str(reqVars["attempts"]))
if reqVars["attempts"] < 500:
reqVars["attempts"] += 1
performSearch()
else:
reqVars["attempts"] = 0
print("Too many requests. Wait for a few minutes then try again.")
prompt = input("\x1b[38;5;110;1m" + "Enter" + "\033[0m" + " Retry " + "\x1b[38;5;110;1m" + "E" + "\033[0m" + " Quit.\n")
if prompt == 'e':
exit()
else:
performSearch()
else:
reqVars["attempts"] = 0
searchResultsPrompt()
def searchResultsPrompt(addedToFavStatus=False):
addToFavText = "(wip)"
if addedToFavStatus:
addToFavText = " Added to favorites."
prompt = input("\n" + "\33[33;1m" + "F" + "\033[0m" + addToFavText + "\n" +"\x1b[38;5;110;1m" + "Enter" + "\033[0m" + " New Search " + "\x1b[38;5;110;1m" + "E" + "\033[0m" + " Quit.\n")
if prompt != 'e' and prompt != 'f':
performSearch()
elif prompt == 'f' and prompt != 'e':
addToFavs()
searchResultsPrompt(addedToFavStatus=True)
def clearScreen():
os.system('cls' if os.name == 'nt' else 'clear')
def title():
print("\n\n" + '\033[1m' + "PyPlaceRoulette" + "\033[0;0m" + " by splatert" )
def getPlaceAvailability(universeID):
placeStatusParams = {'universeIds': universeID}
cookies = {'.ROBLOSECURITY': myRobloSecurityKey}
getPlaceStatus = requests.get("https://games.roblox.com/v1/games/multiget-playability-status", params=placeStatusParams, cookies=cookies)
if getPlaceStatus.status_code == 200:
placeStatus = getPlaceStatus.json()
playability = placeStatus[0]["playabilityStatus"]
if playability == "Playable":
return True
else:
return False
def multigetPlaceInfo(placeID):
print("Reading place details...")
session = requests.Session()
cookies = {'.ROBLOSECURITY': myRobloSecurityKey}
params = {'placeIds': placeID}
getPlaceInfo = requests.get("https://games.roblox.com/v1/games/multiget-place-details", cookies=cookies, params=params)
placeInfoTemplate = {
"placeId": 0,
"name": "Loading...",
"sourceName": "Loading...",
"description": "Loading...",
"sourceDescription": "Loading...",
"url": "https://www.roblox.com/games/1844238/Fjorkavills-Hellgate",
"builder": "Loading...",
"builderId": 0,
"isPlayable": True,
"reasonProhibited": "None",
"universeId": 420602,
"universeRootPlaceId": 1844238,
}
if getPlaceInfo.status_code == 200:
placeInfo = getPlaceInfo.json()
if len(placeInfo) > 0:
# fill in array with place details
keysToTake = ["placeId", "name", "description", "builder", "isPlayable"]
for key in keysToTake:
if placeInfo[0][key]:
placeInfoTemplate[key] = placeInfo[0][key]
else:
placeInfoTemplate[key] = "Could not fetch."
print("[OK]", end=" ")
return placeInfoTemplate
else:
return "ErrNotValidPlace"
else:
print("[Error] Not a place. Performing new search...")
return "ErrNotValidPlace"
def placeIsNotTemplate(placeName):
valid = False
if placeName.endswith("'s Place"):
valid = False
else:
valid = True
return valid
def fastSearch():
searchFailed = False
placeID = createPlaceID()
place = multigetPlaceInfo(placeID)
if place == "ErrNotValidPlace":
searchFailed = True
else:
placeDetails = place
if settings["SkipStarterPlaces"]:
notAStarterPlace = placeIsNotTemplate(placeDetails["name"])
if notAStarterPlace == False:
searchFailed = True
if settings["SkipPrivatePlaces"]:
if placeDetails["isPlayable"] == "true":
searchFailed = False
elif placeDetails["isPlayable"] == "false":
searchFailed = True
if not searchFailed:
print("\n" + '\033[1m' + placeDetails["name"] + "\033[0;0m" + " [ " + placeDetails["url"] + " ] " )
print("Created by: " + placeDetails["builder"])
if settings["ViewPlaceInWebBrowser"]:
if not searchFailed:
viewPlaceInWebBrowser(placeID)
return searchFailed
def main():
title()
print("\nChoose randomizer.")
print("A. Standard")
print("D. Fast\n\n")
prompt = input("\x1b[38;5;110;1m" + "A/D" + "\033[0m" + " Choose " + "\x1b[38;5;110;1m" + "E" + "\033[0m" + " Quit.\n")
if prompt == "a" or prompt == "d":
if prompt == "a":
reqVars["searchMode"] = 1
elif prompt == "d":
reqVars["searchMode"] = 2
#print("mode: " + str(reqVars["searchMode"]))
performSearch()
elif prompt == "e":
clearScreen()
exit()
main()