-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.py
89 lines (76 loc) · 2.65 KB
/
source.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# The main source code file
# Импорт системных модулей
import requests
import datetime
import time
import os
# Импорт локальных файлов с настройками и коммандами
import config
import commands
import bus_command
from data_storage import *
# Импорт класса для обработки изменений на сервере
from bothandler import BotHandler as handler
# Создание бота с заданным токеном
skaffer = handler(config.token)
def main():
new_offset = None
while True:
# Получение информации с сервера
skaffer.get_updates(new_offset)
last_update = skaffer.get_last_update()
# При получении непустого ответа с сервера
if last_update != {}:
try:
last_update_id = last_update['update_id']
last_chat_text = last_update['message']['text'].lower()
last_chat_id = last_update['message']['chat']['id']
last_chat_name = last_update['message']['chat']['first_name']
except KeyError as key_error_message:
print("Exception while obtaining data from server", key_error_message)
if last_chat_text in start_dict:
commands.start(last_chat_id, last_chat_name)
elif last_chat_text in weather_dict:
commands.weather(last_chat_id)
elif last_chat_text in next_dict:
commands.next(last_chat_id)
elif last_chat_text in help_dict:
commands.help(last_chat_id)
elif last_chat_text in tt_dict:
commands.timetable(last_chat_id)
elif last_chat_text in tod_dict:
commands.today_timetable(last_chat_id)
elif last_chat_text in tom_dict:
commands.tomorrow_timetable(last_chat_id)
elif last_chat_text in bus47_dict:
bus_command.bus(last_chat_id)
elif last_chat_text == 'курчатова':
bus_command.kurch(last_chat_id)
elif last_chat_text == 'факультет радиофизики':
bus_command.raf(last_chat_id)
elif last_chat_text in alt_dict:
commands.alt(last_chat_id)
elif last_chat_text in greet_dict:
greet_msg = last_chat_text
greet_msg += ', '
greet_msg += last_chat_name
greet_msg += ' :)'
skaffer.send_message(last_chat_id, greet_msg)
else:
err_msg = 'Я тебя не понял, '
err_msg += last_chat_name
err_msg += ' :(\nИспользуй /help, чтобы узнать, что я умею'
skaffer.send_message(last_chat_id, err_msg)
log = ''
log += str(last_chat_id)
log += ' typed '
log += '['
log += last_chat_text
log += ']'
print(log)
new_offset = last_update_id + 1
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
exit()