-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoints.py
executable file
·30 lines (26 loc) · 1.15 KB
/
points.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
#!/usr/bin/env python3
from contextlib import closing
import sqlite3
points = {}
with closing(sqlite3.connect("ddnet-server.sqlite")) as con:
con.row_factory = sqlite3.Row
with closing(con.cursor()) as cur:
cur.execute("DELETE FROM record_points")
cur.execute("SELECT DISTINCT Name, Map FROM record_race")
finishes = cur.fetchall()
for finish in finishes:
if not finish["Map"] in points:
cur.execute("SELECT Points FROM record_maps WHERE Map = ?", [finish["Map"]])
points_row = cur.fetchone()
if points_row is None:
print("Failed to look up points for map '%s'" % finish["Map"])
exit(1)
points[finish["Map"]] = points_row["Points"]
cur.execute(
"INSERT INTO record_points (Name, Points) "
"VALUES (?, ?) "
"ON CONFLICT(Name) DO UPDATE SET Points=Points+?;",
(finish["Name"], points[finish["Map"]], points[finish["Map"]])
)
print("%s +%d %s" % (finish["Map"], points[finish["Map"]], finish["Name"]))
con.commit()