-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
38 lines (27 loc) · 1015 Bytes
/
Copy pathbot.py
File metadata and controls
38 lines (27 loc) · 1015 Bytes
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
import asyncio
import requests
from aiogram import Bot, Dispatcher, executor, types
from aiogram.utils.markdown import hlink
from scraper import ParserTesmania
from config import token, channel_id
tesmania = ParserTesmania()
tesmania.login()
bot = Bot(token=token, parse_mode=types.ParseMode.HTML)
dp = Dispatcher(bot)
async def get_fresh_articles():
while True:
try:
fresh = tesmania.get_spacex()
fresh.update(tesmania.get_tesla())
if len(fresh) >= 1:
for key, value in fresh.items():
article = f"{hlink(value['article_title'], value['article_url'])}"
print("send message")
await bot.send_message(chat_id=channel_id, text=article)
await asyncio.sleep(15)
except requests.exceptions.HTTPError:
tesmania.login()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.create_task(get_fresh_articles())
executor.start_polling(dp)