-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
62 lines (45 loc) · 1.89 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
51
52
53
54
55
56
57
58
59
60
61
62
from modules.pickings import *
from modules.aeon import *
from modules.ald import *
import lxml
import os
import random
from telegram.ext import Updater, Dispatcher, CommandHandler
import requests
import telepot
from bs4 import BeautifulSoup
import urllib.request
import logging
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
YOUR_TOKEN = 'secret!'
WELCOME = 'Welcome! I am PhilDailyBot, here to give you your dose of philosophy, life, love and everything else in between! \n Type the following commands for making use of this bot. \n /brainpickings for an article from Brain Pickings \n /aeon for an article from Aeon \n /ald for an article from Arts and Letters Daily.'
def brain_pickings(bot,update):
final_reply = get_pickings()
bot.send_message(chat_id=update.message.chat_id,text=final_reply)
def my_start(bot,update):
final_reply = WELCOME
bot.send_message(chat_id=update.message.chat_id,text=final_reply)
def aeonco(bot,update):
final_reply = get_aeon()
bot.send_message(chat_id=update.message.chat_id,text=final_reply)
def aldaily(bot,update):
final_reply = get_ald()
bot.send_message(chat_id=update.message.chat_id,text=final_reply)
def error(bot, update, error):
"""Log Errors caused by Updates."""
logger.warning('Update "%s" caused error "%s"', update, error)
#mybot = telepot.Bot()
updater = Updater(token=YOUR_TOKEN)
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler('start', my_start))
dispatcher.add_handler(CommandHandler('brainpickings', brain_pickings))
dispatcher.add_handler(CommandHandler('aeon', aeonco))
dispatcher.add_handler(CommandHandler('ald', aldaily))
dispatcher.add_error_handler(error)
updater.start_polling()
print('it is happening!')
updater.idle()
print('it is idle!')