From c7ffe13e335217ce5a991ecab11ca7abcb77ba50 Mon Sep 17 00:00:00 2001 From: brucewzj99 Date: Sun, 30 Jul 2023 22:29:08 +0800 Subject: [PATCH] added checks for tracker --- bot/google_sheet.py | 5 +- bot/telegram_bot.py | 31 +++++++++++- release_notes.md | 117 ++++++++++++++++++++++---------------------- test.py | 3 ++ 4 files changed, 95 insertions(+), 61 deletions(-) diff --git a/bot/google_sheet.py b/bot/google_sheet.py index 4aa6a26..b021e1e 100644 --- a/bot/google_sheet.py +++ b/bot/google_sheet.py @@ -157,7 +157,10 @@ def get_trackers(sheet_id): .execute() ) values = result.get("values", []) - return values[0] + if values: + return values[0] + else: + return def update_rows(sheet_id, day, new_row, first_row): diff --git a/bot/telegram_bot.py b/bot/telegram_bot.py index e2a64b7..ffba7bd 100644 --- a/bot/telegram_bot.py +++ b/bot/telegram_bot.py @@ -97,8 +97,35 @@ def set_up(update, context) -> int: current_datetime = dt.datetime.now(timezone) day = current_datetime.day month = current_datetime.strftime("%b") - gs.update_rows(sheet_id, day, 4, 5) # New users start from row 5 - gs.create_date(sheet_id, day, month, 5) + + # get tracker data to check if got input + trackers = gs.get_trackers(sheet_id) + if trackers: # If got input + day_tracker = int(trackers[0]) + first_row = int(trackers[3]) + if day_tracker == day: + pass + elif day_tracker < day: + prev_month = (current_datetime - dt.timedelta(days=1)).strftime( + "%b" + ) + gs.update_prev_day(sheet_id, prev_month, first_row) + new_row = gs.get_new_row(sheet_id, month) + first_row = new_row + 1 + gs.update_rows(sheet_id, day, new_row, first_row) + gs.create_date(sheet_id, day, month, first_row) + elif day == 1: + new_row = 4 + first_row = 5 + gs.update_rows(sheet_id, day, new_row, first_row) + gs.create_date(sheet_id, day, month, first_row) + else: # New sheet + new_row = 4 + first_row = 5 + gs.update_rows( + sheet_id, day, new_row, first_row + ) # New users start from row 5 + gs.create_date(sheet_id, day, month, first_row) update.message.reply_text(SUCCESS_LINK_TEXT) return ConversationHandler.END except Exception as e: diff --git a/release_notes.md b/release_notes.md index 7ad66cf..c1da0c3 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,55 +1,34 @@ # Release Notes -## Version 1.0.0 - Date: 20 May 2023 -- Initial Launch - -## Version 1.1.0 - Date: 21 May 2023 -### New Features 🆕 -- Back button -- Added help command - -### Bug Fixes 🛠️ -- Remove 'Transport' category from others -- Fixed others and transport row tracker -- Fixed first row tracker - -### Enhancement 🔥 -- Refactor file structure - -## Version 1.2.0 - Date: 24 May 2023 -### New Features 🆕 (Planned deployment: 27 May 2023) -- Retrieve past transaction with /retrievetransaction command -- Add income with /addincome command - -### Enhancement 🔥 -- Increase number of options for add others - -## Version 2.0.0 - Date 28 May 2023 -### Enhancement 🔥 -- Cloud hosting w Flask & Vercel 🎉 -- Move string to text_str.py +## Version 2.1.5 - Date 30 July 2023 +### Bug Fix 🛠️ +- Added tracker check when adding google sheet to prevent resetting of (existing) tracker +## Version 2.1.4 - Date 16 July 2023 ### Bug Fix 🛠️ -- Allow negative price entry +- Added end conversation handler for get day transaction -### To note ❗ -- Remove sql functions -- python-telegram-bot library changed to 13.7 -- Move services account to environment variable -- Please read the new README for developer +## Version 2.1.3 - Date 16 July 2023 +### Enhancement 🔥 +- Allows user to add multiple settings for quick transport + - If there is only one settings, that will be used as default (/addtransport only) +- Revamp Google Sheet with new looks -## Version 2.0.1 - Date 1 Jun 2023 ### Bug Fix 🛠️ -- Fix month abbreviation -- Fix updating of previous month +- Skip empty cells for payment & category ### For Developer 🧑‍💻 -- Added a new updates.py file to push updates to all users -- To run updates, call functions in push_updates.py +- Remove firebase codes -## Version 2.0.2 - Date 1 Jun 2023 +## Version 2.1.2 - Date 26 Jun 2023 ### Bug Fix 🛠️ -- Day 1 sum creation bug +- When new users join, new date entry was not created +- Quick add settings not sending proper error message when either transport or others has been configured + +## Version 2.1.1 - Date 8 Jun 2023 +### Enhancement 🔥 +- Migrate to use firestore +- Reformatted get overall transaction ## Version 2.1.0 - Date 1 Jun 2023 ### New Features 🆕 @@ -61,31 +40,53 @@ ### For Developer 🧑‍💻 - When you run test.py, ngrok will auto setup with the correct webhook! +## Version 2.0.2 - Date 1 Jun 2023 +### Bug Fix 🛠️ +- Day 1 sum creation bug -## Version 2.1.1 - Date 8 Jun 2023 +## Version 2.0.1 - Date 1 Jun 2023 +### Bug Fix 🛠️ +- Fix month abbreviation +- Fix updating of previous month + +### For Developer 🧑‍💻 +- Added a new updates.py file to push updates to all users +- To run updates, call functions in push_updates.py + +## Version 2.0.0 - Date 28 May 2023 ### Enhancement 🔥 -- Migrate to use firestore -- Reformatted get overall transaction +- Cloud hosting w Flask & Vercel 🎉 +- Move string to text_str.py -## Version 2.1.2 - Date 26 Jun 2023 ### Bug Fix 🛠️ -- When new users join, new date entry was not created -- Quick add settings not sending proper error message when either transport or others has been configured +- Allow negative price entry +### To note ❗ +- Remove sql functions +- python-telegram-bot library changed to 13.7 +- Move services account to environment variable +- Please read the new README for developer + +## Version 1.2.0 - Date: 24 May 2023 +### New Features 🆕 (Planned deployment: 27 May 2023) +- Retrieve past transaction with /retrievetransaction command +- Add income with /addincome command -## Version 2.1.3 - Date 16 July 2023 ### Enhancement 🔥 -- Allows user to add multiple settings for quick transport - - If there is only one settings, that will be used as default (/addtransport only) -- Revamp Google Sheet with new looks +- Increase number of options for add others -### Bug Fix 🛠️ -- Skip empty cells for payment & category +## Version 1.1.0 - Date: 21 May 2023 +### New Features 🆕 +- Back button +- Added help command -### For Developer 🧑‍💻 -- Remove firebase codes +### Bug Fixes 🛠️ +- Remove 'Transport' category from others +- Fixed others and transport row tracker +- Fixed first row tracker +### Enhancement 🔥 +- Refactor file structure -## Version 2.1.4 - Date 16 July 2023 -### Bug Fix 🛠️ -- Added end conversation handler for get day transaction \ No newline at end of file +## Version 1.0.0 - Date: 20 May 2023 +- Initial Launch \ No newline at end of file diff --git a/test.py b/test.py index 326e4a1..d2a3dd1 100644 --- a/test.py +++ b/test.py @@ -28,4 +28,7 @@ def index(): if __name__ == "__main__": public_url = ngrok.connect(5000, "http").public_url updater.bot.set_webhook(url=f"{public_url}/webhook") + print("#" * 50) + print(f"# Bot is running at @{updater.bot.get_me().username} #") + print("#" * 50) app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))