aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2021-02-12 14:58:25 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2021-02-12 14:58:25 +0200
commit99c8b7c679616a22274b1ce6abcc57e404a1a3a1 (patch)
tree32fe0f32c2ac948bc16c6212dbc918efdbfd1086
parent6d69d7f19c3014318734e618baff5ba958fe2344 (diff)
Send actual sheets data as message
-rw-r--r--hommaexceli_py/main.py11
-rw-r--r--hommaexceli_py/sheets_client.py3
-rw-r--r--hommaexceli_py/telegram_client.py7
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,
)