|
@@ -24,8 +24,8 @@ def check_vote(db, vote_name, user_id): # Check if user has already voted on th
|
|
|
return False
|
|
return False
|
|
|
if row[0] == user_id:
|
|
if row[0] == user_id:
|
|
|
return True
|
|
return True
|
|
|
- except Error as cverror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t check if {user_id} already voted on \"{vote_name}\": {cverror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as cverror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t check if {user_id} already voted on \"{vote_name}\": {cverror}')
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_to_vote(db, vote_name, user_id): # Add a count to a vote
|
|
def add_to_vote(db, vote_name, user_id): # Add a count to a vote
|
|
@@ -45,8 +45,8 @@ def add_to_vote(db, vote_name, user_id): # Add a count to a vote
|
|
|
)
|
|
)
|
|
|
db.commit()
|
|
db.commit()
|
|
|
return True
|
|
return True
|
|
|
- except Error as terror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t add to \"{vote_name}\" vote: {terror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as terror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t add to \"{vote_name}\" vote: {terror}')
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
@@ -58,8 +58,8 @@ def add_to_queue(db, user_id, reward_name): # Add a reward to the queue
|
|
|
)
|
|
)
|
|
|
db.commit()
|
|
db.commit()
|
|
|
return True
|
|
return True
|
|
|
- except Error as qerror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t add to reward \"{reward_name}\" for {user_id} queue: {qerror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as qerror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t add to reward \"{reward_name}\" for {user_id} queue: {qerror}')
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
@@ -67,7 +67,7 @@ def run_script(reward_name, script_cmd): # Run a script form a special reward
|
|
|
try:
|
|
try:
|
|
|
subprocess.check_call(script_cmd, shell=True)
|
|
subprocess.check_call(script_cmd, shell=True)
|
|
|
except Exception as scerror:
|
|
except Exception as scerror:
|
|
|
- current_app.logger.error(f'Couldn\'t run script \"{reward_name}\": {scerror.args[0]}')
|
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t run script \"{reward_name}\": {scerror}')
|
|
|
return False
|
|
return False
|
|
|
return True
|
|
return True
|
|
|
|
|
|
|
@@ -94,8 +94,8 @@ def add_to_goal(db, user_id, reward_name, points_contributed): # Add a contribu
|
|
|
)
|
|
)
|
|
|
db.commit()
|
|
db.commit()
|
|
|
return True
|
|
return True
|
|
|
- except Error as gerror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t update goal: {gerror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as gerror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t update goal: {gerror}')
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
@@ -112,8 +112,8 @@ def goal_left(db, reward_name):
|
|
|
progress, target = row
|
|
progress, target = row
|
|
|
left = target - progress
|
|
left = target - progress
|
|
|
return left
|
|
return left
|
|
|
- except Error as glerror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t check progress for \"{reward_name}\" goal: {glerror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as glerror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t check progress for \"{reward_name}\" goal: {glerror}')
|
|
|
|
|
|
|
|
|
|
|
|
|
def goal_reached(db, reward_name): # Set a goal as completed
|
|
def goal_reached(db, reward_name): # Set a goal as completed
|
|
@@ -127,8 +127,8 @@ def goal_reached(db, reward_name): # Set a goal as completed
|
|
|
current_app.logger.error(f'{reward_name} not found in goal table.')
|
|
current_app.logger.error(f'{reward_name} not found in goal table.')
|
|
|
else:
|
|
else:
|
|
|
return row[0]
|
|
return row[0]
|
|
|
- except Error as grerror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t check if goal was met: {grerror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as grerror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t check if goal was met: {grerror}')
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
@@ -195,8 +195,8 @@ def was_milestone_reached(db, reward_name): # Check if a milestone was reached
|
|
|
else:
|
|
else:
|
|
|
return False
|
|
return False
|
|
|
return False
|
|
return False
|
|
|
- except Error as wmrerror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t check if a milestone was reached: {wmrerror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as wmrerror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t check if a milestone was reached: {wmrerror}')
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
@@ -219,8 +219,8 @@ def was_goal_reached(db, reward_name): # Check if a goal was reached
|
|
|
db.commit()
|
|
db.commit()
|
|
|
return True
|
|
return True
|
|
|
return False
|
|
return False
|
|
|
- except Error as wgrerror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t mark goal met: {wgrerror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as wgrerror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t mark goal met: {wgrerror}')
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
@@ -230,8 +230,8 @@ def all_votes(db): # Get all the votes
|
|
|
"SELECT votes.name, votes.count, votes.info FROM votes"
|
|
"SELECT votes.name, votes.count, votes.info FROM votes"
|
|
|
)
|
|
)
|
|
|
return cursor.fetchall()
|
|
return cursor.fetchall()
|
|
|
- except Error as aterror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t select all votes: {aterror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as aterror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t select all votes: {aterror}')
|
|
|
|
|
|
|
|
|
|
|
|
|
def refund_reward(db, reward_id): # Refund a user for a particular reward
|
|
def refund_reward(db, reward_id): # Refund a user for a particular reward
|
|
@@ -244,8 +244,8 @@ def refund_reward(db, reward_id): # Refund a user for a particular reward
|
|
|
db.commit()
|
|
db.commit()
|
|
|
current_app.logger.info(f'Set {reward_id} as refunded in the database')
|
|
current_app.logger.info(f'Set {reward_id} as refunded in the database')
|
|
|
return True
|
|
return True
|
|
|
- except Error as rferror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t refund reward id {reward_id}: {rferror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as rferror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t refund reward id {reward_id}: {rferror}')
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
@@ -259,8 +259,8 @@ def fulfill_reward(db, reward_id): # Mark a reward as fulfilled in the database
|
|
|
db.commit()
|
|
db.commit()
|
|
|
current_app.logger.info(f'{reward_id} marked fulfilled.')
|
|
current_app.logger.info(f'{reward_id} marked fulfilled.')
|
|
|
return True
|
|
return True
|
|
|
- except Error as frerror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t fulfill reward id {reward_id}: {frerror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as frerror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t fulfill reward id {reward_id}: {frerror}')
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
@@ -283,7 +283,7 @@ def all_goals(db): # Get all the goals
|
|
|
)
|
|
)
|
|
|
return cursor.fetchall()
|
|
return cursor.fetchall()
|
|
|
except Exception as agerror:
|
|
except Exception as agerror:
|
|
|
- current_app.logger.error(f'Couldn\'t select all goals: {agerror.args[0]}')
|
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t select all goals: {agerror}')
|
|
|
|
|
|
|
|
|
|
|
|
|
def all_active_goals(db): # Get only active goals
|
|
def all_active_goals(db): # Get only active goals
|
|
@@ -330,7 +330,7 @@ def save_alerts(alerts_dict): # Write alerts to alerts.py
|
|
|
af.close
|
|
af.close
|
|
|
current_app.logger.info('Saved new alerts.py.')
|
|
current_app.logger.info('Saved new alerts.py.')
|
|
|
except Exception as saerror:
|
|
except Exception as saerror:
|
|
|
- current_app.logger.error(f'Couldn\'t save alerts.py: {saerror.args[0]}')
|
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t save alerts.py: {saerror}')
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
current_app.config.from_pyfile('alerts.py', silent=True) # Reread alerts.py into the app
|
|
current_app.config.from_pyfile('alerts.py', silent=True) # Reread alerts.py into the app
|
|
@@ -365,7 +365,7 @@ def save_rewards(reward_info): # Write rewards to rewards.py
|
|
|
rf.write(f'REWARDS = {new_rewards}')
|
|
rf.write(f'REWARDS = {new_rewards}')
|
|
|
rf.close()
|
|
rf.close()
|
|
|
except Exception as srerror:
|
|
except Exception as srerror:
|
|
|
- current_app.logger.error(f'Couldn\'t save rewards.py: {srerror.args[0]}')
|
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t save rewards.py: {srerror}')
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
return True
|
|
@@ -391,7 +391,7 @@ PREFIX = '{config_dict['PREFIX']}'"
|
|
|
cf.write(new_settings)
|
|
cf.write(new_settings)
|
|
|
cf.close
|
|
cf.close
|
|
|
except Exception as scerror:
|
|
except Exception as scerror:
|
|
|
- current_app.logger.error(f'Couldn\'t save config.py: {scerror.args[0]}')
|
|
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t save config.py: {scerror}')
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
current_app.config.from_pyfile('config.py', silent=True) # Reread config.py into the app
|
|
current_app.config.from_pyfile('config.py', silent=True) # Reread config.py into the app
|
|
@@ -414,8 +414,8 @@ def reread_categories(): # Read _CAT varaibles and write to categories.py
|
|
|
f.close
|
|
f.close
|
|
|
|
|
|
|
|
current_app.config.from_pyfile('categories.py', silent=True) # Reread categories into the app
|
|
current_app.config.from_pyfile('categories.py', silent=True) # Reread categories into the app
|
|
|
- except Error as rcerror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t reread categories: {rcerror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as rcerror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t reread categories: {rcerror}')
|
|
|
|
|
|
|
|
|
|
|
|
|
def activate_category(category): # Move an item from the ACTIVE_CAT list to the INACTIVE_CAT list
|
|
def activate_category(category): # Move an item from the ACTIVE_CAT list to the INACTIVE_CAT list
|
|
@@ -426,8 +426,8 @@ def activate_category(category): # Move an item from the ACTIVE_CAT list to the
|
|
|
active_categories.append(category) # Add to ACTIVE_CAT
|
|
active_categories.append(category) # Add to ACTIVE_CAT
|
|
|
inactive_categories.remove(category) # Remove from INACTIVE_CAT
|
|
inactive_categories.remove(category) # Remove from INACTIVE_CAT
|
|
|
reread_categories()
|
|
reread_categories()
|
|
|
- except Error as acerror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t activate {category}: {acerror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as acerror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t activate {category}: {acerror}')
|
|
|
|
|
|
|
|
|
|
|
|
|
def deactivate_category(category): # Move an item from the INACTIVE_CAT list to the ACTIVE_CAT list
|
|
def deactivate_category(category): # Move an item from the INACTIVE_CAT list to the ACTIVE_CAT list
|
|
@@ -438,8 +438,8 @@ def deactivate_category(category): # Move an item from the INACTIVE_CAT list to
|
|
|
active_categories.remove(category) # Remove from ACTIVE_CAT
|
|
active_categories.remove(category) # Remove from ACTIVE_CAT
|
|
|
inactive_categories.append(category) # Add to INACTIVE_CAT
|
|
inactive_categories.append(category) # Add to INACTIVE_CAT
|
|
|
reread_categories()
|
|
reread_categories()
|
|
|
- except Error as dcerror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t deactivate {category}: {dcerror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as dcerror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t deactivate {category}: {dcerror}')
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_queue(db): # Get the reward queue and the username
|
|
def get_queue(db): # Get the reward queue and the username
|
|
@@ -451,8 +451,8 @@ def get_queue(db): # Get the reward queue and the username
|
|
|
on reward_queue.user_id = points.id"""
|
|
on reward_queue.user_id = points.id"""
|
|
|
)
|
|
)
|
|
|
return cursor.fetchall()
|
|
return cursor.fetchall()
|
|
|
- except Error as gqerror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t get queue: {gqerror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as gqerror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t get queue: {gqerror}')
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_reward_active(reward_name): # Check if reward is active
|
|
def is_reward_active(reward_name): # Check if reward is active
|
|
@@ -470,5 +470,5 @@ def is_reward_active(reward_name): # Check if reward is active
|
|
|
else:
|
|
else:
|
|
|
return True
|
|
return True
|
|
|
return None
|
|
return None
|
|
|
- except Error as iraerror:
|
|
|
|
|
- current_app.logger.error(f'Couldn\'t check if {reward_name} is active: {iraerror.args[0]}')
|
|
|
|
|
|
|
+ except Exception as iraerror:
|
|
|
|
|
+ current_app.logger.error(f'Couldn\'t check if {reward_name} is active: {iraerror}')
|