-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
50 lines (34 loc) · 1.39 KB
/
main.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
import logging
import datetime
import json
import pytz
from telegram import Update, Bot
from telegram.ext import Updater, CommandHandler, CallbackContext
from utils import workflow
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
with open("secret.json", "r") as secret:
data = json.load(secret)
token = data["token"]
channel_id = data["channel_id"]
def start_command(update: Update, context: CallbackContext):
bot = Bot(token=token)
update.message.reply_text("Hey there!")
def morning(context: CallbackContext):
message = workflow()
if not message:
message = "No important news for today"
context.bot.send_message(channel_id, text=message, parse_mode="HTML", disable_web_page_preview=True)
def help_command(update: Update, context: CallbackContext):
update.message.reply_text('This bot is used in CTI News channel')
def main():
updater = Updater(token)
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler("start", start_command))
dispatcher.add_handler(CommandHandler("help", help_command))
j = updater.job_queue
j.run_daily(morning, days=(0, 1, 2, 3, 4, 5, 6), time=datetime.time(hour=9, minute=30, second=00, tzinfo=pytz.timezone('Europe/Kiev')))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()