Handle keyboard interrupt
Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
parent
23be5d6cc3
commit
5bd5d9da92
1 changed files with 30 additions and 27 deletions
|
@ -85,31 +85,34 @@ db = pymysql.connect("localhost", dbuser, dbpw, "worldbuild")
|
||||||
|
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
|
|
||||||
while True:
|
try:
|
||||||
sql = "SELECT topLevel.name AS topLevelName, status.name AS statusName, COUNT(*) AS sCount from secondLevel JOIN topLevel ON secondLevel.parent_id = topLevel.id JOIN status ON secondLevel.status_id = status.id GROUP BY status.id, topLevelName"
|
while True:
|
||||||
cursor.execute(sql)
|
sql = "SELECT topLevel.name AS topLevelName, status.name AS statusName, COUNT(*) AS sCount from secondLevel JOIN topLevel ON secondLevel.parent_id = topLevel.id JOIN status ON secondLevel.status_id = status.id GROUP BY status.id, topLevelName"
|
||||||
rows = cursor.fetchall()
|
cursor.execute(sql)
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
status = {}
|
status = {}
|
||||||
for row in rows:
|
for row in rows:
|
||||||
if not row[0] in status:
|
if not row[0] in status:
|
||||||
status[row[0]] = {}
|
status[row[0]] = {}
|
||||||
status[row[0]][row[1]] = row[2]
|
status[row[0]][row[1]] = row[2]
|
||||||
|
|
||||||
sql = "SELECT topLevel.name, status.name FROM topLevel JOIN status ON topLevel.status_id = status.id"
|
sql = "SELECT topLevel.name, status.name FROM topLevel JOIN status ON topLevel.status_id = status.id"
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
status[row[0]]["status"] = row[1]
|
status[row[0]]["status"] = row[1]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(fname, "w") as f:
|
with open(fname, "w") as f:
|
||||||
json.dump(status, f, indent=4)
|
json.dump(status, f, indent=4)
|
||||||
except IOError:
|
except IOError:
|
||||||
print("ERROR: Failed to write to file")
|
print("ERROR: Failed to write to file")
|
||||||
|
|
||||||
if repeat == 0:
|
if repeat == 0:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
sleep(repeat * 60)
|
sleep(repeat * 60)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Exiting...")
|
||||||
|
|
Loading…
Add table
Reference in a new issue