-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscrapeTimelines.py
More file actions
44 lines (27 loc) · 765 Bytes
/
scrapeTimelines.py
File metadata and controls
44 lines (27 loc) · 765 Bytes
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
import urllib.request
import json
import time
import os
apiKey = ''
gamesArray = []
for filename in os.listdir('jsons'):
gamesArray.append(filename)
i = 0
while i < len(gamesArray):
print(str(i))
gameId = gamesArray[i].replace('.json', '')
urlString = 'https://euw1.api.riotgames.com/lol/match/v3/timelines/by-match/'+str(gameId)+'?api_key=' + apiKey
try:
with urllib.request.urlopen(urlString) as url:
json_raw = url.read().decode()
dataGame = json.loads(json_raw)
json_file = open('jsons/timeline/{}.json'.format(str(gameId)), 'wb')
json_file.write(json_raw.encode('utf-8'))
json_file.close
except urllib.error.HTTPError as err:
print(str(err))
if err.code == 429:
print('sleeping 2')
time.sleep(25)
i-=1
i += 1