-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcollectMatches.py
More file actions
38 lines (32 loc) · 1.12 KB
/
collectMatches.py
File metadata and controls
38 lines (32 loc) · 1.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
import databaseHandler as db
import riotAPIHandler as api
import time
import threading
def insertMatch(matchId):
print(matchId)
# check match
response = api.getMatch(matchId, "euw", True)
# if this Id belongs to a match
if type(response) is dict:
# insert it into the database
t = threading.Thread(target=insertIntoDatabase, args=(response,))
t.daemon = False
t.start()
# if the match was played in the last 2 hours wait a bit so we don't
# overlook games which are currently still running
if (response["matchCreation"] + 7200000) > int(time.time()*1000):
print("We're getting kinda close to currently played games. Sleeping for 5 minutes")
time.sleep(300)
return True
def insertIntoDatabase(data):
db.insertMatch(data)
# get the last match we collected
result = db.selectFetchOne("SELECT matchId FROM lol.match ORDER BY idmatch DESC")
# if no matches are collected yet use this Id as entry point
if result is None:
matchId = 1792756886
else:
matchId = result[0] + 1
while True:
insertMatch(matchId)
matchId += 1