-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
38 lines (31 loc) · 1.08 KB
/
main.py
File metadata and controls
38 lines (31 loc) · 1.08 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
import asyncio
import logging
from config import token
from aiogram import Bot, Dispatcher, executor
from parse import parse
from database import SqLighter
from keyboards import news_keyboard
db=SqLighter('database.db')
logging.basicConfig(level=logging.INFO)
bot = Bot(token, parse_mode="HTML")
dp = Dispatcher(bot)
async def scheduled(wait_for):
while True:
await asyncio.sleep(wait_for)
news = str(parse())
text = f"🔔 На сайте опубликована новая запись!\n<b>{news}</b>"
f = open('latest_news_id.txt')
latest_news = f.read()
f.close()
if latest_news != news:
f = open('latest_news_id.txt', 'w')
f.write(news)
f.close()
subscriptions = db.get_subscriptions()
for s in subscriptions:
await bot.send_message(s[1], text=text, reply_markup=news_keyboard)
if __name__ == '__main__':
from handlers import dp
loop = asyncio.get_event_loop()
loop.create_task(scheduled(60))
executor.start_polling(dp, skip_updates=True)