-
Notifications
You must be signed in to change notification settings - Fork 0
/
puller.py
150 lines (118 loc) · 7.2 KB
/
puller.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
import requests
import json
import os
import time
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
import datetime
def get_key(team, level):
s = requests.Session()
retries = Retry(total=10,
status_forcelist=[443, 429, 500, 502, 503, 504])
s.mount('http://', HTTPAdapter(max_retries=retries))
url = f'https://raider.io/api/teams/mythic-plus/dungeon-runs?season=season-df-3&team={team}®ion=us&dungeon={level}'
r = s.get(url, timeout=120)
text = r.json()
try:
return text["viewTeamMythicPlusDungeonRunsApi"]["runs"]
except:
return json.loads('{"viewTeamMythicPlusDungeonRunsApi":{"runs":[],"ui":{"season":"season-df-3","team":"'+team+'","region":"us","dungeon":"'+level+'","namespace":"default"}}}')["viewTeamMythicPlusDungeonRunsApi"]["runs"]
# return json.loads('{"viewTeamMythicPlusDungeonRunsApi":{"runs":[{"summary":{"season":"season-df-3","status":"finished","dungeon":{"id":7673,"name":"Darkheart Thicket","short_name":"DHT","slug":"darkheart-thicket","expansion_id":6,"icon_url":"/images/wow/icons/large/achievement_dungeon_darkheartthicket.jpg","patch":"7.0","keystone_timer_ms":1800999,"num_bosses":4,"group_finder_activity_ids":[426,436,446,460]},"keystone_run_id":2440367,"mythic_level":17,"clear_time_ms":1553612,"keystone_time_ms":1800999,"completed_at":"2023-11-20T03:51:33.000Z","num_chests":1,"time_remaining_ms":247387,"logged_run_id":966105,"videos":[],"weekly_modifiers":[{"id":10,"icon":"ability_toughness","name":"Fortified","description":"Non-boss enemies have 20% more health and inflict up to 30% increased damage."},{"id":136,"icon":"achievement_boss_anomalus","name":"Incorporeal","description":"While in combat, incorporeal beings periodically appear and attempt to weaken players."},{"id":8,"icon":"spell_shadow_bloodboil","name":"Sanguine","description":"When slain, non-boss enemies leave behind a lingering pool of ichor that heals their allies and damages players."}],"num_modifiers_active":3,"faction":"alliance","deleted_at":null,"role":"tank"},"score":150.71701233593134}],"ui":{"season":"season-df-3","team":"manastorm-apologists","region":"us","dungeon":"darkheart-thicket","namespace":"default"}}}')["viewTeamMythicPlusDungeonRunsApi"]["runs"]
def get_chest_plus(plus_count):
if plus_count == 0:
return ""
if plus_count == 1:
return "+"
if plus_count == 2:
return "++"
if plus_count == 3:
return "+++"
def main():
st = os.stat('score.json')
mtime = st.st_mtime
c_time = time.time()
dtime = c_time - mtime
with open('score.json') as f:
json_file = json.load(f)
if dtime > 1 or len(json_file) != 6:
with open("teams.txt", "r") as file:
teams = file.readlines()
with open("dungeon.txt", "r") as file:
dungeons = file.readlines()
team_store = {}
for team in teams:
print(team.strip("\n"))
top = {}
for dungeon in dungeons:
team = team.strip("\n")
dungeon = dungeon.strip("\n")
data = get_key(team, dungeon)
keys_store_fort = []
keys_store_tryan = []
top_keys = {"Fortified": {}, "Tyrannical": {}}
if data:
for key in data:
# for i in key["summary"]:
# print(i)
#
if key["summary"]["time_remaining_ms"] > 0:
if key['summary']["weekly_modifiers"][0]["name"] == "Tyrannical":
keys_store_tryan.append(key['summary']['mythic_level'])
elif key['summary']["weekly_modifiers"][0]["name"] == "Fortified":
keys_store_fort.append(key['summary']['mythic_level'])
try:
max_key_fort = max(keys_store_fort)
except:
max_key_fort = 0
top_keys["Fortified"] = {"key_level": 0, "percent": 0,
"plus": ""}
try:
max_key_tryan = max(keys_store_tryan)
except:
max_key_tryan = 0
top_keys["Tyrannical"] = {"key_level": 0, "percent": 0,
"plus": ""}
try:
for key in data:
if max_key_fort == key['summary']['mythic_level'] and key['summary']["weekly_modifiers"][0]["name"] == "Fortified":
if key['summary']['mythic_level'] != 0:
key_time = round((key['summary']["clear_time_ms"] / key['summary']["keystone_time_ms"]) * 100)
plus = get_chest_plus(key['summary']['num_chests'])
top_keys["Fortified"] = {"key_level": key['summary']['mythic_level'], "percent": key_time, "plus": plus}
else:
print("asd")
if max_key_tryan == key['summary']['mythic_level'] and key['summary']["weekly_modifiers"][0]["name"] == "Tyrannical":
if key['summary']['mythic_level'] != 0:
key_time = round((key['summary']["clear_time_ms"] / key['summary']["keystone_time_ms"]) * 100)
plus = get_chest_plus(key['summary']['num_chests'])
top_keys["Tyrannical"] = {"key_level": key['summary']['mythic_level'], "percent": key_time, "plus": plus}
else:
print("asd")
top[key['summary']['dungeon']['name']] = top_keys
except Exception as e:
print(e)
else:
top_keys["Tyrannical"] = {"key_level": 0, "percent": 0, "plus": ""}
top_keys["Fortified"] = {"key_level": 0, "percent": 0, "plus": ""}
top[dungeon] = top_keys
team_store[team] = top
json.dump(team_store, open('score.json', 'w'), sort_keys=True, indent=4, separators=(',', ': '))
return team_store
else:
return json_file
if __name__ == '__main__':
data = main()
json.dump(data, open('score.json', 'w'), sort_keys=True, indent=4, separators=(',', ': '))
# max_key = max(keys_store)
# for key in data:
# if max_key == key['summary']['mythic_level'] and key['summary']["weekly_modifiers"][0][
# "name"] == ability_toughness:
# key_time = round((key['summary']["clear_time_ms"] / key['summary']["keystone_time_ms"]) * 100)
# plus = get_chest_plus(key['summary']['num_chests'])
# top[key_name][ability_toughness] = {
# ability_toughness: {"key_level": key['summary']['mythic_level'], "percent": key_time, "plus": plus,
# "ability": ability_toughness}}
# print(top)
# except Exception as e:
# print(e)
# pass