|
@@ -5,6 +5,7 @@ from flask.cli import with_appcontext
|
|
import click
|
|
import click
|
|
from time import time
|
|
from time import time
|
|
import os
|
|
import os
|
|
|
|
+import logging
|
|
|
|
|
|
|
|
|
|
def rem_from_queue(reward_name): # Remove a reward from the queue
|
|
def rem_from_queue(reward_name): # Remove a reward from the queue
|
|
@@ -16,7 +17,7 @@ def rem_from_queue(reward_name): # Remove a reward from the queue
|
|
)
|
|
)
|
|
db.commit()
|
|
db.commit()
|
|
except sqlite3.Error as rfqerror:
|
|
except sqlite3.Error as rfqerror:
|
|
- print(f'Couldn\'t remove {reward_name} from reward queue: {rfqerror.args[0]}')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t remove {reward_name} from reward queue: {rfqerror.args[0]}')
|
|
return False
|
|
return False
|
|
return True
|
|
return True
|
|
|
|
|
|
@@ -95,7 +96,7 @@ def clear_reward_queue(): # Completely clear the reward queue
|
|
)
|
|
)
|
|
db.commit()
|
|
db.commit()
|
|
except sqlite3.Error as serror:
|
|
except sqlite3.Error as serror:
|
|
- print(f'Couldn\'t clear reward queue: {serror.args[0]}')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t clear reward queue: {serror.args[0]}')
|
|
return False
|
|
return False
|
|
return True
|
|
return True
|
|
|
|
|
|
@@ -109,7 +110,7 @@ def clear_fulfilled_rewards(): # Clears only fulfilled rewards from the queue
|
|
)
|
|
)
|
|
db.commit()
|
|
db.commit()
|
|
except sqlite3.Error as serror:
|
|
except sqlite3.Error as serror:
|
|
- print(f'Couldn\'t clear fulfilled rewards: {serror.args[0]}')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t clear fulfilled rewards: {serror.args[0]}')
|
|
return False
|
|
return False
|
|
return True
|
|
return True
|
|
|
|
|
|
@@ -121,7 +122,7 @@ def rem_all_votes(): # USED TO BE "clear_votes" Clear all votes from the databa
|
|
db.execute("DELETE FROM votes")
|
|
db.execute("DELETE FROM votes")
|
|
db.commit()
|
|
db.commit()
|
|
except sqlite3.Error as cverror:
|
|
except sqlite3.Error as cverror:
|
|
- print(f'Couldn\'t clear all votes: {cverror.args[0]}')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t clear all votes: {cverror.args[0]}')
|
|
return False
|
|
return False
|
|
if put_votes(db):
|
|
if put_votes(db):
|
|
return True
|
|
return True
|
|
@@ -134,7 +135,7 @@ def rem_vote(): # Remove a single vote from the database
|
|
db.execute("DELETE FROM votes WHERE name = ?", ('vote',))
|
|
db.execute("DELETE FROM votes WHERE name = ?", ('vote',))
|
|
db.commit()
|
|
db.commit()
|
|
except sqlite3.Error as rverror:
|
|
except sqlite3.Error as rverror:
|
|
- print(f'Couldn\'t remove \"{vote}\" from database: {rverror.args[0]}')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t remove \"{vote}\" from database: {rverror.args[0]}')
|
|
return False
|
|
return False
|
|
if put_votes(db):
|
|
if put_votes(db):
|
|
return True
|
|
return True
|
|
@@ -152,7 +153,7 @@ def is_cool(reward_name): # Check if a reward is cooling down.
|
|
)
|
|
)
|
|
current_cds = cursor.fetchall()
|
|
current_cds = cursor.fetchall()
|
|
except sqlite3.Error as icerror:
|
|
except sqlite3.Error as icerror:
|
|
- print(f'Couldn\'t get \"{reward_name}\" from database: {icerror.args[0]}')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t get \"{reward_name}\" from database: {icerror.args[0]}')
|
|
if current_cds:
|
|
if current_cds:
|
|
last_time = current_cds[0][0]
|
|
last_time = current_cds[0][0]
|
|
hot_time = current_time - last_time
|
|
hot_time = current_time - last_time
|
|
@@ -168,7 +169,7 @@ def is_cool(reward_name): # Check if a reward is cooling down.
|
|
db.commit()
|
|
db.commit()
|
|
return True, 0
|
|
return True, 0
|
|
except sqlite3.Error as scerror:
|
|
except sqlite3.Error as scerror:
|
|
- print(f'Couldn\'t update \"{reward_name}\"\'s cooldown time in the database: {scerror.args[0]}')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t update \"{reward_name}\"\'s cooldown time in the database: {scerror.args[0]}')
|
|
else: # If it is not in the database, add it and return True
|
|
else: # If it is not in the database, add it and return True
|
|
try:
|
|
try:
|
|
db.execute(
|
|
db.execute(
|
|
@@ -178,7 +179,7 @@ def is_cool(reward_name): # Check if a reward is cooling down.
|
|
db.commit()
|
|
db.commit()
|
|
return True, 0
|
|
return True, 0
|
|
except sqlite3.Error as scerror:
|
|
except sqlite3.Error as scerror:
|
|
- print(f'Couldn\'t add \"{reward_name}\" to database: {scerror.args[0]}')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t add \"{reward_name}\" to database: {scerror.args[0]}')
|
|
else: # If the redeem has no cooldown
|
|
else: # If the redeem has no cooldown
|
|
return True, 0
|
|
return True, 0
|
|
|
|
|
|
@@ -191,7 +192,7 @@ def rem_cool(reward_name): # Remove a reward from the database
|
|
)
|
|
)
|
|
current_cds = cursor.fetchall()
|
|
current_cds = cursor.fetchall()
|
|
except sqlite3.Error as icerror:
|
|
except sqlite3.Error as icerror:
|
|
- print(f'Couldn\'t remove \"{reward_name}\" from database: {icerror.args[0]}')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t remove \"{reward_name}\" from database: {icerror.args[0]}')
|
|
return False
|
|
return False
|
|
return True
|
|
return True
|
|
|
|
|
|
@@ -207,7 +208,7 @@ def put_votes(db): # Reread votes from rewards.py, and sync with database
|
|
)
|
|
)
|
|
db.commit()
|
|
db.commit()
|
|
except sqlite3.Error as serror:
|
|
except sqlite3.Error as serror:
|
|
- print(f'Couldn\'t insert \"{vote}\" into database: {serror.args[0]}')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t insert \"{vote}\" into database: {serror.args[0]}')
|
|
return False
|
|
return False
|
|
return True
|
|
return True
|
|
|
|
|
|
@@ -229,7 +230,7 @@ def reread_votes(): # Reread votes from rewards.py, and sync with database
|
|
cursor.execute("DELETE FROM votes WHERE name = ?", (vote,))
|
|
cursor.execute("DELETE FROM votes WHERE name = ?", (vote,))
|
|
db.commit()
|
|
db.commit()
|
|
except sqlite3.Error as serror:
|
|
except sqlite3.Error as serror:
|
|
- print(f'Couldn\'t clear deleted votes from database: {serror.args[0]}')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t clear deleted votes from database: {serror.args[0]}')
|
|
return False
|
|
return False
|
|
|
|
|
|
try: # Add new votes found in rewards.py
|
|
try: # Add new votes found in rewards.py
|
|
@@ -254,7 +255,7 @@ def reread_votes(): # Reread votes from rewards.py, and sync with database
|
|
)
|
|
)
|
|
db.commit()
|
|
db.commit()
|
|
except sqlite3.Error as serror:
|
|
except sqlite3.Error as serror:
|
|
- print(f'Couldn\'t insert \"{vote}\" into database: {serror.args[0]}')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t insert \"{vote}\" into database: {serror.args[0]}')
|
|
return False
|
|
return False
|
|
return True
|
|
return True
|
|
|
|
|
|
@@ -276,7 +277,7 @@ def reread_goals(): # Reread goals from rewards.py, and sync with database
|
|
cursor.execute("DELETE FROM goals WHERE name = ?", (goal,))
|
|
cursor.execute("DELETE FROM goals WHERE name = ?", (goal,))
|
|
db.commit()
|
|
db.commit()
|
|
except sqlite3.Error as serror:
|
|
except sqlite3.Error as serror:
|
|
- print(f'Couldn\'t clear removed goals from database: {serror.args[0]}')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t clear removed goals from database: {serror.args[0]}')
|
|
return False
|
|
return False
|
|
|
|
|
|
try: # Add new goals found in rewards.py
|
|
try: # Add new goals found in rewards.py
|
|
@@ -299,14 +300,14 @@ def reread_goals(): # Reread goals from rewards.py, and sync with database
|
|
)
|
|
)
|
|
db.commit()
|
|
db.commit()
|
|
except sqlite3.Error as serror:
|
|
except sqlite3.Error as serror:
|
|
- print(f'Couldn\'t insert \"{reward}\" into database: {serror.args[0]}')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t insert \"{reward}\" into database: {serror.args[0]}')
|
|
return False
|
|
return False
|
|
return True
|
|
return True
|
|
|
|
|
|
|
|
|
|
def reset_goal(goal): # Set goal progress back to zero
|
|
def reset_goal(goal): # Set goal progress back to zero
|
|
if goal not in current_app.config['REWARDS']: # If it doesn't exist in rewards.py
|
|
if goal not in current_app.config['REWARDS']: # If it doesn't exist in rewards.py
|
|
- print(f'Couldn\'t reset goal, {goal} not in rewards file.')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t reset goal, {goal} not in rewards file.')
|
|
return False
|
|
return False
|
|
try:
|
|
try:
|
|
db = get_db()
|
|
db = get_db()
|
|
@@ -326,7 +327,7 @@ def reset_goal(goal): # Set goal progress back to zero
|
|
|
|
|
|
def reset_vote(vote):
|
|
def reset_vote(vote):
|
|
if vote not in current_app.config['REWARDS']: # Check if it exists in rewards.py
|
|
if vote not in current_app.config['REWARDS']: # Check if it exists in rewards.py
|
|
- print(f'Couldn\'t reset vote, {vote} not in rewards file.')
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t reset vote, {vote} not in rewards file.')
|
|
return False
|
|
return False
|
|
else:
|
|
else:
|
|
try:
|
|
try:
|