diff --git a/push_information.py b/push_information.py index 630c507..46e8edd 100644 --- a/push_information.py +++ b/push_information.py @@ -95,10 +95,15 @@ def schedule_subscriptions(): schedule.default_scheduler.clear() for user in users.values(): for sub in user.subs: - sub.city.query_weather() - schedule.default_scheduler.every().day.at(time.strftime("%H:%M", sub.time)).do( - send_message, chat_id=user.chat_id, message=str(sub.city.weather)) - sub.city.weather.clear() + schedule.default_scheduler.every().day.at(time.strftime("%H:%M", sub.time)).do(handle_subscription, + chat_id=user.chat_id, + sub=sub) + + +def handle_subscription(chat_id: int, sub: Subscription): + sub.city.query_weather() + send_message(chat_id=chat_id, message=sub.city.get_weather_str()) + sub.city.weather.clear() def push_callback(update: Update, context: CallbackContext): diff --git a/weather_openweathermap.py b/weather_openweathermap.py index 84d2ddf..6c9afc0 100644 --- a/weather_openweathermap.py +++ b/weather_openweathermap.py @@ -168,6 +168,9 @@ class City: def print_weather(self): print(self.weather) + def get_weather_str(self) -> str: + return f"Weather for *{self.name}*:\n" + str(self.weather) + def get_city_by_name(city_name: str) -> City: with open("city.list.json", "r") as city_list_file: @@ -218,6 +221,6 @@ def handle_weather(update, context): if requested_city.name == "none": raise WeatherStationNotFoundError requested_city.query_weather() - update.message.reply_text(str(requested_city.weather), disable_notification=True, parse_mode=ParseMode.MARKDOWN) + update.message.reply_text(requested_city.get_weather_str(), disable_notification=True, parse_mode=ParseMode.MARKDOWN) requested_city.weather.clear()