-
Notifications
You must be signed in to change notification settings - Fork 0
/
omaRandomizer.py
81 lines (71 loc) · 2.72 KB
/
omaRandomizer.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
import requests, json, time, webbrowser, datetime
from random import randrange
from collections import defaultdict
URL = 'https://oma.hwc.hr/api/pools/'
def print_beatmap(beatmap, auto_osu=False, auto_bloodcat=False):
print(f"""Your beatmap is:
{beatmap['mapName']} [{beatmap['difficultyName']}]
Star Rating: {str(beatmap['starRating'])}
Bloodcat Link: {'https://bloodcat.com/osu/s/' + str(beatmap['mapSetId'])}
osu!direct Link: {'osu://b/' + str(beatmap['mapId'])}
""")
webbrowser.open('osu://b/' + str(beatmap['mapId']), autoraise=False)
def get_pool():
json_pool = requests.get(URL).content
pools = json.loads(json_pool)
dated_pool = {'refreshDate': str(datetime.datetime.today()), 'pools': pools}
with open("omaPool.json", "wt") as file_pool:
json.dump(dated_pool, file_pool)
return pools
try:
with open("omaPool.json", "rt") as file_pool:
dated_pool = json.load(file_pool)
refreshDate = datetime.datetime.strptime(dated_pool['refreshDate'], r"%Y-%m-%d %H:%M:%S.%f")
if ((datetime.datetime.today() - refreshDate) < datetime.timedelta(days=7)):
print("Local pool isn't 7 days old. Reusing...")
pools = dated_pool['pools']
else:
print("Local pool is 7 days old. Grabbing latest...")
pools = get_pool()
except FileNotFoundError:
pools = get_pool()
print("Local pool does not exist. Grabbing latest...")
max_mmr = float(input("Max MMR = "))
min_mmr = float(input("Min MMR = "))
if max_mmr < min_mmr:
min_mmr, max_mmr = max_mmr, min_mmr
filtered_pools = [pool for pool in pools if (min_mmr < float(pool['averageMMR']) < max_mmr)]
maps = defaultdict(list)
for pool in filtered_pools:
for beatmap in pool['maps']:
maps[beatmap['sheetId']].append(beatmap)
while True:
try:
mapset = input("Mapset = ").upper()
if mapset == '':
break
elif mapset == 'INFO':
for key in maps.keys():
print(key + ": " + str(len(maps[key])))
print("")
continue
except KeyboardInterrupt:
break
try:
if len(maps[mapset]) == 0:
print(f"You have played all {mapset} maps in the elo range!")
for key in maps.keys():
print(key + ": " + str(len(maps[key])))
print("")
continue
rand_beatmap = randrange(0, len(maps[mapset]))
beatmap = maps[mapset].pop(rand_beatmap)
print_beatmap(beatmap)
time.sleep(10)
except KeyError:
print("Mapset not recognized. These are the only mapsets available:")
for key in maps.keys():
print(key + " " + str(len(maps[key])))
print("")
except KeyboardInterrupt:
continue