word_cloud_bot/main.py

30 lines
979 B
Python
Raw Normal View History

2021-05-05 02:59:30 +00:00
from telegram.ext import Updater
from config import TOKEN
2021-05-08 02:18:24 +00:00
from func import start_handler, chat_content_handler, check_schedule, rank_handler
2021-05-05 08:13:28 +00:00
import schedule
2021-05-08 02:18:24 +00:00
from task import schedule_task, flush_redis, do_task
2021-05-05 08:13:28 +00:00
import threading
2021-05-08 02:18:24 +00:00
schedule.every().day.at('11:00').do(schedule_task)
schedule.every().day.at('18:00').do(schedule_task)
schedule.every().day.at('23:30').do(schedule_task)
2021-05-05 10:17:21 +00:00
schedule.every().day.at('23:59').do(flush_redis)
2021-05-08 02:18:24 +00:00
# 测试代码,每分钟推送数据,非测试目的不要取消注释下一行
# schedule.every(1).minutes.do(schedule_task)
2021-05-05 08:13:28 +00:00
2021-05-08 02:18:24 +00:00
# 开启分析线程,当队列中由任务时,会取出任务分析生成数据
threading.Thread(target=do_task).start()
2021-05-05 08:13:28 +00:00
threading.Thread(target=check_schedule).start()
2021-05-05 02:59:30 +00:00
updater = Updater(token=TOKEN, use_context=True)
dispatcher = updater.dispatcher
dispatcher.add_handler(start_handler)
2021-05-08 02:18:24 +00:00
dispatcher.add_handler(rank_handler)
2021-05-05 03:10:01 +00:00
dispatcher.add_handler(chat_content_handler)
2021-05-05 02:59:30 +00:00
updater.start_polling()
updater.idle()