From de329587cb8868872e7cd3f61e8cc9c152866c1d Mon Sep 17 00:00:00 2001 From: Lukas Winkler Date: Wed, 2 Oct 2019 17:52:19 +0200 Subject: [PATCH] initial version --- .gitignore | 4 ++++ main.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .gitignore create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..da320eb --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +config.py +.idea +cache.json +__pycache__/ diff --git a/main.py b/main.py new file mode 100644 index 0000000..487a9ad --- /dev/null +++ b/main.py @@ -0,0 +1,38 @@ +import json + +import requests +import telegram +from bs4 import BeautifulSoup + +from config import telegram_token, telegram_chat_id + +try: + with open("cache.json") as f: + cache = json.load(f) +except FileNotFoundError: + cache = {} + +s = requests.Session() + + +def notify(text): + print(text) + bot = telegram.Bot(token=telegram_token) + message = "🌩ī¸đŸŒĒī¸đŸŒ€\n" + text + bot.sendMessage(chat_id=telegram_chat_id, text=message) + + +for day in ["heute", "morgen", "uebermorgen"]: + r = s.get(f'https://warnungen.zamg.at/html/de/{day}/wind/at/wien/wien_waehring/wien_waehring/') + + soup = BeautifulSoup(r.text, 'html.parser') + warnings = [tag.get_text() for tag in soup.find_all("p", class_="warnung_text")] + text = "\n".join(warnings) + if day not in cache or text != cache[day]: + # if text: + notify(text) + cache[day] = text + print(text) + +with open("cache.json", "w") as f: + json.dump(cache, f)