aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@valuemotive.com>2021-02-14 17:51:34 +0200
committerJan Tuomi <jan.tuomi@valuemotive.com>2021-02-14 17:51:34 +0200
commit34dc42bca46397118cf4f53e2f119eea1d56cdc1 (patch)
tree210dfa562ce16a5bba7ed1ac8b624792ab973acd
parentbd2f7811b1f1633e150642222a9e07b5dd7a375a (diff)
Fix last done column updatingmaster
-rw-r--r--hommaexceli_py/data_parser.py8
-rw-r--r--hommaexceli_py/sheets_client.py7
-rw-r--r--hommaexceli_py/telegram_client.py9
3 files changed, 16 insertions, 8 deletions
diff --git a/hommaexceli_py/data_parser.py b/hommaexceli_py/data_parser.py
index f72b05f..7df78ba 100644
--- a/hommaexceli_py/data_parser.py
+++ b/hommaexceli_py/data_parser.py
@@ -41,7 +41,7 @@ def _process_row(row: SheetsRow):
next_date = last_done_date + interval
next_date_str = _date_to_timestamp(next_date)
else:
- last_done_date = datetime.datetime.now()
+ last_done_date = None
next_date = datetime.datetime.now()
next_date_str = _date_to_timestamp(next_date)
@@ -69,3 +69,9 @@ def _is_this_week(processed_row: ProcessedRow):
def filter_only_this_week(rows: list[ProcessedRow]) -> list[ProcessedRow]:
return [row for row in rows if _is_this_week(row)]
+
+
+def updated_last_done_datestamps(rows: list[ProcessedRow]) -> list[str]:
+ return [
+ row.next_datestamp if _is_this_week(row) else row.last_datestamp for row in rows
+ ]
diff --git a/hommaexceli_py/sheets_client.py b/hommaexceli_py/sheets_client.py
index 242dca8..36dabb2 100644
--- a/hommaexceli_py/sheets_client.py
+++ b/hommaexceli_py/sheets_client.py
@@ -89,16 +89,13 @@ def fetch_sheet_data(service: Resource) -> list[SheetsRow]:
return [_row_to_dataclass(row) for row in rows]
-def update_sheet_last_done_column(
- service: Resource, processed_rows: list[ProcessedRow]
-):
+def update_sheet_last_done_column(service: Resource, new_datestamps: list[str]):
logging.info("Calling Sheets API to update last done column...")
range = getenv("SHEETS_RANGE")
sheet = service.spreadsheets()
last_done_column_range = _get_rightmost_column_in_range(range)
- # Update last done date to match next date
- body = {"values": list(map(lambda row: [row.next_datestamp], processed_rows))}
+ body = {"values": [[datestamp] for datestamp in new_datestamps]}
sheet.values().update(
spreadsheetId=getenv("SHEETS_SPREADSHEET_ID"),
diff --git a/hommaexceli_py/telegram_client.py b/hommaexceli_py/telegram_client.py
index bf5a614..9f0a42c 100644
--- a/hommaexceli_py/telegram_client.py
+++ b/hommaexceli_py/telegram_client.py
@@ -13,7 +13,11 @@ from sheets_client import (
fetch_sheet_data,
update_sheet_last_done_column,
)
-from data_parser import filter_only_this_week, process_rows
+from data_parser import (
+ filter_only_this_week,
+ process_rows,
+ updated_last_done_datestamps,
+)
from functools import partial
@@ -54,7 +58,8 @@ def _callback_alarm(context: CallbackContext, sheets_service: Resource):
context.bot.send_message(chat_id=chat_id, text=message)
- update_sheet_last_done_column(sheets_service, processed_rows)
+ new_datestamps = updated_last_done_datestamps(processed_rows)
+ update_sheet_last_done_column(sheets_service, new_datestamps)
def _callback_timer(update: Update, context: CallbackContext, sheets_service: Resource):