Repository navigation
Expand file tree
/
Copy pathbot.py
More file actions
56 lines (44 loc) · 1.36 KB
/
Copy pathbot.py
File metadata and controls
56 lines (44 loc) · 1.36 KB
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
from telegram import Bot
from telegram import Update
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from bs4 import BeautifulSoup
import re
import requests
import logging
from config import TG_TOKEN
from config import TG_API_URL
from config import URL
from main import parse
def alarm(context):
result = parse()
to_string = ''.join(result).replace("'", '')
try:
pattern = re.compile(r'[{|}}]')
sentences = filter(lambda t: t, [t.strip()
for t in pattern.split(to_string)])
for s in sentences:
# update.message.reply_text(f'{s}')
context.bot.send_message(chat_id=context.job.context, text=f'{s}')
except:
# update.message.reply_text(result)
context.bot.send_message(chat_id=context.job.context, text=result)
def start(update, context):
chat_id = update.message.chat_id
context.job_queue.run_repeating(alarm, 3600, 0, context=chat_id)
def main():
bot = Bot(
token=TG_TOKEN,
base_url=TG_API_URL,
)
updater = Updater(
bot=bot,
use_context=True
)
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
logging.info('msg')
main()