Guest User

Untitled

a guest
Oct 22nd, 2017
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. def attendance(bot, job):
  2.     # Get chatID and user details based on chatID from the database
  3.     update = job.context
  4.     chatID = update.message.chat_id
  5.     if not Chat.query.filter(Chat.chatID == chatID).first():
  6.         bot.sendMessage(chat_id=update.message.chat_id, text="SOME MESSAGE")
  7.         return
  8.     userChat = Chat.query.filter(Chat.chatID == chatID).first()
  9.     PID = userChat.PID
  10.     password = userChat.password
  11.  
  12.     #Empty the previous report contents
  13.     ...
  14.  
  15.     configure_logging({'LOG_FORMAT': '%(levelname)s: %(message)s'})
  16.     runner = CrawlerRunner({
  17.         'FEED_FORMAT': 'json',
  18.         'FEED_URI' : 'output.json'
  19.         })
  20.  
  21.     d = runner.crawl(MySpider, USERNAME=PID, PASSWORD=password)
  22.     d.addBoth(lambda _: reactor.stop())
  23.     reactor.run(installSignalHandlers=0)
  24.  
  25.     ...
  26.     #SOME DATA PROCESSING FROM SCRAPPED ITEMS
  27.  
  28.     #Send message with processed data
  29.     bot.sendMessage(chat_id=update.message.chat_id, text=messageContent)
  30.  
  31.     #RESTART BOT TO COUNTER ReactorNotRestartable Error.
  32.     time.sleep(0.2)
  33.     os.execl(sys.executable, sys.executable, *sys.argv)
Add Comment
Please, Sign In to add comment