From 74e22f533bcac64d6e53b98435f5663c475954fc Mon Sep 17 00:00:00 2001 From: norohind <60548839+norohind@users.noreply.github.com> Date: Wed, 3 Nov 2021 21:21:03 +0300 Subject: [PATCH] add update thursday mode --- main.py | 20 ++++++++++++++++---- sql_requests.py | 7 ++++++- utils.py | 10 ++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index aba7b6b..bafca54 100644 --- a/main.py +++ b/main.py @@ -142,9 +142,11 @@ def discover(back_count: int = 0): tries = tries + 1 -def update(squad_id: int = None, amount_to_update: int = 1): +def update(squad_id: int = None, amount_to_update: int = 1, thursday_target: bool = False): """ + :param thursday_target: if we aiming to update all squads before thursday (FDEV scheduled maintenance) + and we don't wanna update squads which already updated after previous thursday :param squad_id: update specified squad, updates only that squad :param amount_to_update: update specified amount, ignores when squad_id specified :return: @@ -156,8 +158,18 @@ def update(squad_id: int = None, amount_to_update: int = 1): # suppress_absence is required because if we updating squad with some high id it may just don't exists yet return - logger.debug(f'Going to update {amount_to_update} squadrons') - squads_id_to_update: list = db.execute(sql_requests.select_squads_to_update, (amount_to_update,)).fetchall() + logger.debug(f'Going to update {amount_to_update} squadrons with thursday_target = {thursday_target}') + + if thursday_target: + prev_thursday = f'{utils.get_previous_thursday_date()} 10:30:00' + squads_id_to_update: list = db.execute( + sql_requests.select_squads_to_update_thursday_aimed, (prev_thursday, amount_to_update)).fetchall() + + if len(squads_id_to_update) == 0: + logger.info(f'thursday_target and no squads to update') + + else: + squads_id_to_update: list = db.execute(sql_requests.select_squads_to_update, (amount_to_update,)).fetchall() for single_squad_to_update in squads_id_to_update: # if db is empty, then loop will not happen @@ -207,7 +219,7 @@ if __name__ == '__main__': while True: can_be_shutdown = False - update(amount_to_update=500) + update(amount_to_update=500, thursday_target=True) if shutting_down: exit(0) diff --git a/sql_requests.py b/sql_requests.py index 982d0c5..32b6549 100644 --- a/sql_requests.py +++ b/sql_requests.py @@ -101,4 +101,9 @@ limit 2;""" select_important_before_delete: str = """select name, platform, member_count, tag, user_tags, created from squads_view -where squad_id = ?;""" \ No newline at end of file +where squad_id = ?;""" + +select_squads_to_update_thursday_aimed: str = """select squad_id +from squads_view +where inserted_timestamp < ? +limit ?;""" diff --git a/utils.py b/utils.py index 219cea7..6919998 100644 --- a/utils.py +++ b/utils.py @@ -483,3 +483,13 @@ def append_to_list_in_dict(dict_to_append: dict[str, list[str]], key: str, value dict_to_append.update({key: [value]}) return dict_to_append + + +def get_previous_thursday_date() -> str: + from datetime import date, timedelta + from calendar import THURSDAY + + today = date.today() + offset = (today.weekday() - THURSDAY) % 7 + last_wednesday = today - timedelta(days=offset) + return str(last_wednesday)