Fixed bug where subscription job did not query weather
Also added city name in response
This commit is contained in:
parent
5e598f3e4f
commit
fbb2c65fd0
2 changed files with 13 additions and 5 deletions
|
@ -95,9 +95,14 @@ def schedule_subscriptions():
|
|||
schedule.default_scheduler.clear()
|
||||
for user in users.values():
|
||||
for sub in user.subs:
|
||||
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()
|
||||
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))
|
||||
send_message(chat_id=chat_id, message=sub.city.get_weather_str())
|
||||
sub.city.weather.clear()
|
||||
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue