diff options
| -rw-r--r-- | hommaexceli_py/main.py | 11 | ||||
| -rw-r--r-- | hommaexceli_py/sheets_client.py | 3 | ||||
| -rw-r--r-- | hommaexceli_py/telegram_client.py | 7 |
3 files changed, 8 insertions, 13 deletions
diff --git a/hommaexceli_py/main.py b/hommaexceli_py/main.py index 46d6acb..9c16ba5 100644 --- a/hommaexceli_py/main.py +++ b/hommaexceli_py/main.py @@ -2,21 +2,10 @@ from dotenv import load_dotenv load_dotenv() -from sheets_client import authenticate_and_fetch_sheets_data from telegram_client import run_telegram def main(): - values = authenticate_and_fetch_sheets_data() - - if not values: - print("No data found.") - else: - print("Toistumisväli, Homma, Viimeksi tehty") - print("===") - for row in values: - print(row) - run_telegram() diff --git a/hommaexceli_py/sheets_client.py b/hommaexceli_py/sheets_client.py index 1dd741c..6ce6a16 100644 --- a/hommaexceli_py/sheets_client.py +++ b/hommaexceli_py/sheets_client.py @@ -14,6 +14,9 @@ class SheetsRow: name: str last_done: str + def __str__(self): + return f"{self.interval}, {self.name}, {self.last_done}" + # If modifying these scopes, delete the file token.pickle. SCOPES = ["https://www.googleapis.com/auth/spreadsheets.readonly"] diff --git a/hommaexceli_py/telegram_client.py b/hommaexceli_py/telegram_client.py index 0c7fcf2..108f525 100644 --- a/hommaexceli_py/telegram_client.py +++ b/hommaexceli_py/telegram_client.py @@ -4,6 +4,7 @@ import sys from os import getenv from telegram.ext import Updater, CommandHandler, Job from telegram import Update +from sheets_client import authenticate_and_fetch_sheets_data chats_mem_cache = set() @@ -19,7 +20,9 @@ def _signal_handler(sig, frame): def _callback_alarm(context): - context.bot.send_message(chat_id=context.job.context, text="Alarm") + rows = authenticate_and_fetch_sheets_data() + message = "\n".join(map(str, rows)) + context.bot.send_message(chat_id=context.job.context, text=message) def _callback_timer(update: Update, context): @@ -29,7 +32,7 @@ def _callback_timer(update: Update, context): chats_mem_cache.add(update.message.chat_id) context.job_queue.run_repeating( _callback_alarm, - datetime.timedelta(seconds=1), + datetime.timedelta(seconds=10), context=update.message.chat_id, ) |
