Advertisement
Guest User

Untitled

a guest
Aug 26th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.98 KB | None | 0 0
  1. import config, asyncio
  2. from datetime import datetime
  3. from aiogram import Bot, Dispatcher, executor, types
  4. from aiogram.dispatcher.filters import Command, Text
  5. from aiogram.types.message import Message
  6. import for_telegram
  7.  
  8. loop = asyncio.get_event_loop()
  9. bot = Bot(token=config.TOKEN, parse_mode='HTML') #Инициализация бота
  10. dp = Dispatcher(bot, loop=loop)
  11.  
  12. async def send_to_admin(dp):
  13.     await bot.send_message(chat_id=config.admin_id, text='Бот запущен, введите команду \'/pars\', чтобы выбрать сервис, который вы хотите запарсить')
  14.    
  15. @dp.message_handler(Command('pars'))
  16. async def send_to_admin_2(dp):
  17.     await bot.send_message(chat_id=config.admin_id, text='''Выберите сайт, который будете парсить и напишите команду:
  18. '/fb_on' - facebook, '/inst_on' - instagram, '/twit_on' - twitter, '/yt_on' - youtube, '/rss_on' - rss-летну, а чтобы отключить
  19. '/fb_off' - facebook, '/inst_off' - instagram, '/twit_off' - twitter, '/yt_off' - youtube, '/rss_off' - rss-летну''')
  20.    
  21. @dp.message_handler(Command(['fb_on']))
  22. async def fbp(wait_for):
  23.     while True:
  24.         await asyncio.sleep(wait_for)
  25.         new_post = for_telegram.fb()
  26.         if new_post != 'Изменений нет':
  27.             await bot.send_message(chat_id=config.chat_id, text=new_post)
  28.            
  29.            
  30. @dp.message_handler(Command(['inst_on']))
  31. async def instp(wait_for):
  32.     while True:
  33.         await asyncio.sleep(wait_for)
  34.         new_post = for_telegram.inst()
  35.         if new_post != 'Изменений нет':
  36.             await bot.send_message(chat_id=config.chat_id, text=new_post)
  37.            
  38.            
  39. @dp.message_handler(Command(['twit']))
  40. async def twitp(wait_for):
  41.     while True:
  42.         await asyncio.sleep(wait_for)
  43.         new_post = for_telegram.twit()
  44.         if new_post != 'Изменений нет':
  45.             await bot.send_message(chat_id=config.chat_id, text=new_post)
  46.            
  47.            
  48. @dp.message_handler(Command(['yt']))
  49. async def ytp(wait_for):
  50.     while True:
  51.         await asyncio.sleep(wait_for)
  52.         new_post = for_telegram.yt()
  53.         if new_post != 'Изменений нет':
  54.             await bot.send_message(chat_id=config.chat_id, text=new_post)
  55.        
  56.        
  57. @dp.message_handler(Command(['rss']))
  58. async def rssp(wait_for):
  59.     while True:
  60.         await asyncio.sleep(wait_for)
  61.         new_post = for_telegram.rss()
  62.         if new_post != 'Изменений нет':
  63.             await bot.send_message(chat_id=config.chat_id, text=new_post)
  64.    
  65. if __name__ == '__main__': #Запус бота
  66.     dp.loop.create_task(fbp(30))
  67.     dp.loop.create_task(fbp(30))
  68.     dp.loop.create_task(instp(30))
  69.     dp.loop.create_task(twitp(30))
  70.     dp.loop.create_task(ytp(30))
  71.     dp.loop.create_task(rssp(30))
  72.     executor.start_polling(dp, on_startup=send_to_admin, skip_updates=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement