add refresh-milestones to cli. fix cli errors
This commit is contained in:
parent
c203ce132f
commit
cf8376eebc
|
@ -52,6 +52,7 @@ def create_app(test_config=None):
|
||||||
app.cli.add_command(db.clear_queue_command)
|
app.cli.add_command(db.clear_queue_command)
|
||||||
app.cli.add_command(db.refresh_counters_command)
|
app.cli.add_command(db.refresh_counters_command)
|
||||||
app.cli.add_command(db.refresh_and_clear_command)
|
app.cli.add_command(db.refresh_and_clear_command)
|
||||||
|
app.cli.add_command(db.refresh_milestones_command)
|
||||||
|
|
||||||
# scheduler job for giving points to users
|
# scheduler job for giving points to users
|
||||||
def proxy_job():
|
def proxy_job():
|
||||||
|
|
|
@ -32,7 +32,7 @@ def insert_counters(db):
|
||||||
(redeem,)
|
(redeem,)
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
except Error as e:
|
except sqlite3.Error as e:
|
||||||
print("Failed inserting counters to db:", e.args[0])
|
print("Failed inserting counters to db:", e.args[0])
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ def clear_redeem_queue():
|
||||||
"""UPDATE counters SET count = 0"""
|
"""UPDATE counters SET count = 0"""
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
except Error as e:
|
except sqlite3.Error as e:
|
||||||
print("Error occured deleting redeem queue:", e.args[0])
|
print("Error occured deleting redeem queue:", e.args[0])
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ def refresh_counters():
|
||||||
try:
|
try:
|
||||||
db.execute("DELETE FROM counters")
|
db.execute("DELETE FROM counters")
|
||||||
db.commit()
|
db.commit()
|
||||||
except Error as e:
|
except sqlite3.Error as e:
|
||||||
print("Error occured deleting old counters:", e.args[0])
|
print("Error occured deleting old counters:", e.args[0])
|
||||||
|
|
||||||
for redeem, redeem_info in current_app.config['REDEEMS'].items():
|
for redeem, redeem_info in current_app.config['REDEEMS'].items():
|
||||||
|
@ -77,7 +77,7 @@ def refresh_counters():
|
||||||
(redeem,)
|
(redeem,)
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
except Error as e:
|
except sqlite3.Error as e:
|
||||||
print("Failed inserting counters to db:", e.args[0])
|
print("Failed inserting counters to db:", e.args[0])
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,29 +86,36 @@ def refresh_milestones():
|
||||||
# delete old milestones
|
# delete old milestones
|
||||||
try:
|
try:
|
||||||
cursor = db.execute("SELECT name FROM milestones")
|
cursor = db.execute("SELECT name FROM milestones")
|
||||||
counters = cursor.fetchall()
|
milestones = cursor.fetchall()
|
||||||
to_delete = []
|
to_delete = []
|
||||||
for counter in counters:
|
for milestone in milestones:
|
||||||
print(f"checking counter {counter}")
|
milestone = milestone[0]
|
||||||
if counter not in current_app.config['REDEEMS'].items():
|
print(f"Checking milestone {milestone}")
|
||||||
to_delete.append(counter)
|
if milestone not in current_app.config['REDEEMS'].items():
|
||||||
elif current_app.config['REDEEMS'][counter]['type'] != "milestone":
|
to_delete.append(milestone)
|
||||||
to_delete.append(counter)
|
elif current_app.config['REDEEMS'][milestone]['type'] != "milestone":
|
||||||
cursor.execute("DELETE FROM counters WHERE name IN ?", (to_delete,))
|
to_delete.append(milestone)
|
||||||
|
for milestone in to_delete:
|
||||||
|
cursor.execute("DELETE FROM counters WHERE name = ?", (milestone,))
|
||||||
db.commit()
|
db.commit()
|
||||||
except Error as e:
|
except sqlite3.Error as e:
|
||||||
print("Failed deleting old milestones from db:", e.args[0])
|
print("Failed deleting old milestones from db:", e.args[0])
|
||||||
|
|
||||||
# add new milestones
|
# add new milestones
|
||||||
try:
|
try:
|
||||||
for redeem, redeem_info in current_app.config['REDEEMS'].items():
|
for redeem, redeem_info in current_app.config['REDEEMS'].items():
|
||||||
if redeem_info["type"] == "milestone":
|
if redeem_info["type"] == "milestone":
|
||||||
cursor = db.execute(
|
cursor = db.execute(
|
||||||
"INSERT INTO milestones(name, progress, goal) VALUES(?, 0, 0)",
|
"SELECT goal FROM milestones WHERE name = ?",
|
||||||
(redeem, 0, redeem_info['goal'])
|
(redeem,)
|
||||||
)
|
)
|
||||||
db.commit()
|
if cursor.fetchone() is None:
|
||||||
except Error as e:
|
cursor.execute(
|
||||||
|
"INSERT INTO milestones(name, progress, goal) VALUES(?, 0, ?)",
|
||||||
|
(redeem, redeem_info['goal'])
|
||||||
|
)
|
||||||
|
db.commit()
|
||||||
|
except sqlite3.Error as e:
|
||||||
print("Failed inserting milestones to db:", e.args[0])
|
print("Failed inserting milestones to db:", e.args[0])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
DROP TABLE IF EXISTS counters;
|
DROP TABLE IF EXISTS counters;
|
||||||
DROP TABLE IF EXISTS redeem_queue;
|
DROP TABLE IF EXISTS redeem_queue;
|
||||||
|
DROP TABLE IF EXISTS milestones;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS points (
|
CREATE TABLE IF NOT EXISTS points (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
|
|
Loading…
Reference in New Issue