Skip to content

Commit

Permalink
Adds DB Cleanup Functionality to FireBot (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
acceptableEngineering authored Mar 24, 2023
1 parent 9aebcd1 commit ab34dbd
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions firebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def generate_rich_diff_body(inci_dict, inci_db_entry, event_changes):

# ------------------------------------------------------------------------------

def generate_notif_body(inci_dict, priority_str):
def generate_notif_body(inci_dict):
"""
Returns a string usually passed into send_telegram() with a prepared message
"""
Expand Down Expand Up @@ -674,7 +674,7 @@ def process_alerts(inci_list):
if is_fire(inci): # First time incident is seen, insert into DB
logger.debug('%s not found in DB, new inci', inci['id'])
db.insert(inci)
telegram_json = send_telegram(generate_notif_body(inci, 'normal'), 'high')
telegram_json = send_telegram(generate_notif_body(inci), 'high')

# Message sent successfully, store Telegram message ID
if telegram_json is not False:
Expand Down Expand Up @@ -710,6 +710,8 @@ def process_daily_recap():

send_telegram(notif_body, 'low')

perform_cleanup(process_wildcad_inci_list)

# ------------------------------------------------------------------------------

def nearby_cameras_url(inci_dict):
Expand Down Expand Up @@ -811,6 +813,29 @@ def find_new_id(start =False):

# ------------------------------------------------------------------------------

def perform_cleanup(inci_list):
"""
Removes entries from the DB no longer present in WildWeb
"""
if inci_list:
keep_inci_ids = []

inci_db = tinydb.Query()

for inci in inci_list:
keep_inci_ids.append(inci['id'])

for inci in db.all():
if inci['id'] not in keep_inci_ids:
print("Delete: " + inci['id'])
db.remove(inci_db.id == inci['id'])

return True

return False

# ------------------------------------------------------------------------------

logger.debug('Running from %s', exec_path)

process_wildcad_inci_list = process_wildcad()
Expand Down

0 comments on commit ab34dbd

Please sign in to comment.