From 63044c545f69be6293e14c4f37088209515854d1 Mon Sep 17 00:00:00 2001 From: svitvojimilioni Date: Wed, 7 Feb 2024 17:21:54 -0500 Subject: [PATCH] Dodao funkciju za vreme Upotreba: !vreme - koristi wttr.in api - vraca liniju jednu, lakse je nego da se parsira json - reaguje i na prognoza --- functions.py | 3 +++ scraper_functions.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/functions.py b/functions.py index 94507ce..1b3465a 100644 --- a/functions.py +++ b/functions.py @@ -27,4 +27,7 @@ def command(msg, rcpt): elif msg.startswith("!tasks"): content = sf.getDmzTasks("https://todo.dmz.rs/") return content + elif msg.startswith("!vreme") or msg.startswith("!prognoza"): + _, query = msg.split(" ", 1) + content = sf.get_weather(query) diff --git a/scraper_functions.py b/scraper_functions.py index d4cbfa6..cd70c39 100644 --- a/scraper_functions.py +++ b/scraper_functions.py @@ -48,3 +48,8 @@ def getDmzTasks(url): return result except Exception as e: return e + +def get_weather(city:str) -> str: + url = f"https://wttr.in/{city}?format=3" + resp = requests.get(url) + return resp.content.decode("utf-8").strip()