telegram-bot/weather_meteomedia.py
JuliusFreudenberger 7a24a127c2 Restructured files
Every command handler and related functions are now in seperate files
Also made a seperate exception for not found weather station
2020-09-14 20:41:54 +02:00

23 lines
902 B
Python

from exceptions import NoArgError, WeatherStationNotFoundError
def search_weather_station(query: str):
station_file = open('stations', 'r')
for line in station_file:
if line.casefold().find(query.casefold()) != -1:
station_file.close()
return line
return 'none'
def handle_weather(update, context):
if len(context.args) == 0:
raise NoArgError
station_line = search_weather_station(' '.join(context.args))
if station_line == 'none':
raise WeatherStationNotFoundError
separator_index = station_line.find(' ')
update.message.reply_text('Weather for ' + station_line[separator_index + 1:-1]
+ ':\nhttp://wetterstationen.meteomedia.de/messnetz/vorhersagegrafik/' +
station_line[:separator_index] + '.png',
disable_notification=True)