-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_teams.py
83 lines (62 loc) · 2.65 KB
/
convert_teams.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
import sqlite3
import requests
import json
def dictToArray(d):
if d is not None:
array = [0]*len(d)
for key in d:
array[int(key) - 1] = d[key]
print array
return array
else:
return None
with sqlite3.connect('teams.db') as conn:
with sqlite3.connect('auth.db') as uconn:
with sqlite3.connect('scores.db') as sconn:
c = conn.cursor();
c.execute("SELECT * FROM teams")
for team in c:
u = uconn.cursor()
u.execute("SELECT email FROM users WHERE username=?", (team[1],))
user = u.fetchone()
members = json.loads(team[3])
members_dict = []
index = 1
for member in members:
s = sconn.cursor()
s.execute("SELECT answers FROM speed WHERE indiv_id=?", (str(team[0]) + '-' + str(index),))
speed_answer = s.fetchone()
if speed_answer is not None:
speed_answer = speed_answer[0]
s = sconn.cursor()
s.execute("SELECT answers FROM accuracy WHERE indiv_id=?", (str(team[0]) + '-' + str(index),))
accuracy_answer = s.fetchone()
if accuracy_answer is not None:
accuracy_answer = accuracy_answer[0]
if accuracy_answer is not None and speed_answer is not None:
members_dict.append({
'name': member,
'speed_scores': json.dumps(dictToArray(json.loads(speed_answer))),
'accuracy_scores': json.dumps(dictToArray(json.loads(accuracy_answer)))
})
index += 1
s = sconn.cursor()
s.execute("SELECT answers FROM guts WHERE team_id=?", (str(team[0]),))
guts_answer = s.fetchone()
if guts_answer is not None:
guts_answer = guts_answer[0]
s = sconn.cursor()
s.execute("SELECT answers FROM team WHERE team_id=?", (str(team[0]),))
team_answer = s.fetchone()
if team_answer is not None:
team_answer = team_answer[0]
if user is not None and guts_answer is not None and team_answer is not None:
print 'Uploading: ' + team[2]
payload = {
'user_email': user[0],
'team_name': team[2],
'members': json.dumps(members_dict),
'guts_scores': json.dumps(dictToArray(json.loads(guts_answer))),
'team_scores': json.dumps(dictToArray(json.loads(team_answer)))
}
r = requests.post('http://localhost:8080/add_legacy_team', data=payload)