-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_jobs.py
More file actions
94 lines (75 loc) · 3.31 KB
/
Copy pathcreate_jobs.py
File metadata and controls
94 lines (75 loc) · 3.31 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
from tournament_traversal import Tournament,Tournaments
from typing import TypedDict, List, Dict, Any
import os
def create_download_jobs(data: Tournaments, existing_jobs) -> List[Dict[str, Any]]:
jobs = []
existing_links = {job['url'] for job in existing_jobs}
for tournament in data["tournaments"]:
for match in tournament["matches"]:
# Similarly, parse 'match_id' from match["link"] or another field.
link_parts = match["link"].strip("/").split("/")
year = link_parts[7]
tournament_id = link_parts[8]
match_id = link_parts[9].upper()
link_map = {
"stroke-analysis": (
f"https://itp-atp-sls.infosys-platforms.com/"
f"static/prod/stroke-analysis/v2/{year}/{tournament_id}/{match_id}/data.json"
),
"rally-analysis": (
f"https://itp-atp-sls.infosys-platforms.com/"
f"static/prod/rally-analysis/{year}/{tournament_id}/{match_id}/data.json"
),
"match-beats": (
f"https://itp-atp-sls.infosys-platforms.com/"
f"static/prod/match-beats/{year}/{tournament_id}/{match_id}/data.json"
),
"court-vision": (
f"https://itp-atp-sls.infosys-platforms.com/"
f"static/prod/court-vision/{year}/{tournament_id}/{match_id}/data.json"
),
"stats-keystats": (
f"https://itp-atp-sls.infosys-platforms.com/"
f"static/prod/stats-plus/{year}/{tournament_id}/{match_id}/keystats.json"
),
"stats-ytdstats": (
f"https://itp-atp-sls.infosys-platforms.com/"
f"static/prod/stats-plus/{year}/{tournament_id}/{match_id}/ytdstats.json"
),
"complete": (
f"https://www.atptour.com/-/Hawkeye/"
f"MatchStats/Complete/{year}/{tournament_id}/{match_id}"
)
}
for parsed_type, url in link_map.items():
# Construct local filename: out/<year>/<tournament_id>/<match_id>/<parsed_type>.json
local_path = os.path.join(
"out",
str(year),
tournament_id,
match_id,
f"{parsed_type}.json",
)
if url in existing_links:
continue
job = {
"url": url,
"local_path": local_path,
"parsed_type": parsed_type,
"year": year,
"tournament_id": tournament_id,
"match_id": match_id,
"match": match, # reference to the actual match object
}
jobs.append(job)
return jobs
def main():
import json
with open('jobs.json') as f:
current_jobs = json.load(f)
with open('temp/traverse_temp.json') as f:
tournaments = json.load(f)
with open('jobs.json', 'w') as f:
json.dump(current_jobs + create_download_jobs(tournaments, current_jobs),f, indent=4)
if __name__ == '__main__':
main()