2019-10-11 22:40:28 +02:00
|
|
|
import logging
|
2020-09-24 11:41:17 +02:00
|
|
|
import threading
|
|
|
|
import time
|
2020-05-12 22:29:44 +02:00
|
|
|
|
2020-09-24 11:41:17 +02:00
|
|
|
import schedule
|
2019-10-17 20:19:37 +02:00
|
|
|
from telegram.ext import Updater, CommandHandler, InlineQueryHandler, CallbackQueryHandler
|
2019-10-11 22:40:28 +02:00
|
|
|
|
2019-10-17 19:03:09 +02:00
|
|
|
from exceptions import *
|
2020-09-14 20:41:54 +02:00
|
|
|
from vvs import inline_station_search, handle_vvs, handle_multiple_stations_reply
|
2020-09-18 22:36:37 +02:00
|
|
|
from weather_meteomedia import handle_meteomedia
|
2020-09-24 11:41:17 +02:00
|
|
|
from weather_openweathermap import handle_weather
|
|
|
|
from weather_openweathermap import __init__ as openweathermap_init
|
|
|
|
from push_information import __init__ as push_init
|
|
|
|
|
2019-10-17 19:03:09 +02:00
|
|
|
|
2019-10-11 22:40:28 +02:00
|
|
|
token_file = open("token", "r")
|
|
|
|
updater = Updater(token=token_file.read(), use_context=True)
|
|
|
|
token_file.close()
|
|
|
|
|
|
|
|
dispatcher = updater.dispatcher
|
|
|
|
|
|
|
|
logging.basicConfig(format='%(acstime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
|
|
|
|
2019-10-17 19:03:09 +02:00
|
|
|
|
2020-09-24 11:41:17 +02:00
|
|
|
def send_message(chat_id: int, message: str):
|
|
|
|
dispatcher.bot.send_message(chat_id=chat_id, text=message, disable_notification=True, parse_mode="Markdown")
|
|
|
|
|
|
|
|
|
|
|
|
cease_continuous_run = threading.Event()
|
|
|
|
|
|
|
|
|
|
|
|
class ScheduleThread(threading.Thread):
|
|
|
|
@classmethod
|
|
|
|
def run(cls):
|
|
|
|
while not cease_continuous_run.is_set():
|
|
|
|
schedule.run_pending()
|
|
|
|
time.sleep(10)
|
|
|
|
|
|
|
|
|
2020-05-12 22:27:47 +02:00
|
|
|
def __main__():
|
|
|
|
inline_station_search_handler = InlineQueryHandler(inline_station_search)
|
|
|
|
dispatcher.add_handler(inline_station_search_handler)
|
|
|
|
dispatcher.add_handler(CommandHandler('vvs', handle_vvs))
|
2020-09-18 22:36:37 +02:00
|
|
|
dispatcher.add_handler(CommandHandler('meteomedia', handle_meteomedia))
|
|
|
|
dispatcher.add_handler(CommandHandler("weather", handle_weather))
|
|
|
|
|
2020-09-24 11:41:17 +02:00
|
|
|
openweathermap_init()
|
|
|
|
dispatcher.add_handler(push_init())
|
2019-10-11 22:40:28 +02:00
|
|
|
|
2020-05-12 22:27:47 +02:00
|
|
|
dispatcher.add_error_handler(error_callback)
|
2019-10-11 22:40:28 +02:00
|
|
|
|
2020-09-24 11:12:57 +02:00
|
|
|
dispatcher.add_handler(CallbackQueryHandler(handle_multiple_stations_reply, pattern="^\/vvs"))
|
2020-09-24 11:41:17 +02:00
|
|
|
|
|
|
|
continuous_thread = ScheduleThread()
|
|
|
|
continuous_thread.start()
|
|
|
|
|
2020-05-12 22:27:47 +02:00
|
|
|
updater.start_polling()
|
|
|
|
updater.idle()
|
|
|
|
|
2020-09-24 11:41:17 +02:00
|
|
|
cease_continuous_run.set()
|
|
|
|
|
2020-05-12 22:27:47 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
__main__()
|