blob: 54bb26d3cc7e8def6fda38db088826e028f8dc30 (
plain)
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
|
import json, sys
from pyranking.db import cursor
date = sys.argv[1]
sql = '''SELECT
rankings.place,
players.id,
players.rank,
rankings.score
FROM players
LEFT JOIN rankings
ON players.id = rankings.pid
AND rankings.date = %(date)s
'''
cursor.execute(sql, {'date': date})
result = {}
for row in cursor.fetchall():
if row['place'] is not None:
result[row['id']] = {
'place': int(row['place']),
'rank': float(row['rank']),
'score': float(row['score'])
}
else:
result[row['id']] = {
'rank': float(row['rank'])
}
print json.dumps(result)
|