-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
63 lines (47 loc) · 1.49 KB
/
test.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
import json
import sqlite3
import time
from datetime import datetime
from queue import Queue
from threading import Thread
import requests
from functions import get_player_name_and_id, get_player_stats, get_team_stats, download_replays
# Number of threads
threads = 4
replay_queue = Queue()
# Authorization Header
header = {'Authorization': 'abc123'}
start = datetime.now()
# Create a database connection and a cursor for executing commands.
conn = sqlite3.connect('rl.db', check_same_thread=False)
c = conn.cursor()
# Set up some threads to fetch the enclosures
for i in range(threads):
worker = Thread(target=download_replays,
args=(i, replay_queue, header, c,))
worker.setDaemon(True)
worker.start()
with open('beispiel_list.json') as file:
data = json.load(file)
replay_url = 'https://ballchasing.com/api/replays'
for x in data['list']:
# Construct the replay URL and print it, yeah!
replay_queue.put(x['id'])
# Now wait for the queue to be empty, indicating that we have
# processed all of the downloads.
print('*** Main thread waiting')
replay_queue.join()
print('*** Done')
conn.commit()
conn.close()
# End
end = datetime.now()
print(f'{end-start}')
ranks = [['unranked', 'unranked'],
['bronze-1', 'bronze-3'],
['silver-1', 'silver-3'],
['gold-1', 'gold-3'],
['platinum-1', 'platinum-3'],
['diamond-1', 'diamond-3'],
['champion-1', 'champion-3'],
['grand-champion', 'grand-champion']]