Advertisement
Tankado95

Untitled

Nov 9th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import telepot
  3. import urllib2
  4. from bs4 import BeautifulSoup
  5. import time
  6. from selenium import webdriver
  7. from pprint import pprint
  8. import json
  9.  
  10.  
  11. user_states = [16841227,130979413,22020287]
  12. past_value = -1
  13.  
  14. def handle(msg):
  15.     chat_id = msg['chat']['id']
  16.     user_states.append(chat_id)
  17.     bot.sendMessage(chat_id,'Hello World')
  18.  
  19.  
  20. def sendNews():
  21.         page_url = 'https://goo.gl/KLdxEW'
  22.         page = urllib2.urlopen(page_url)
  23.         soup = BeautifulSoup(page, 'html.parser')
  24.  
  25.         global past_value
  26.         data = json.loads(str(soup))
  27.  
  28.         if((data['fields']['stato_periodo']['integerValue'] == '2') and (past_value != '2')):
  29.             past_value = '2'
  30.             for id in user_states:
  31.                 bot.sendMessage(id, "PROMO INIZIATA")
  32.         if(data['fields']['stato_periodo']['integerValue'] == '1' and (past_value != '1')):
  33.             past_value = '1'
  34.             for id in user_states:
  35.                 bot.sendMessage(id, "Valore a 1")
  36.         if(data['fields']['stato_periodo']['integerValue'] == '3' and (past_value != '3')):
  37.             past_value = '3'
  38.             for id in user_states:
  39.                 bot.sendMessage(id, "Promo terminata")
  40.  
  41.  
  42.  
  43.  
  44. TOKEN = ''
  45.  
  46. bot = telepot.Bot(TOKEN)
  47. bot.message_loop(handle)
  48.  
  49. print 'Listening ...'
  50.  
  51. while 1:
  52.     if(len(user_states)!=0):
  53.         sendNews()
  54.         time.sleep(30)
  55.     else:
  56.         time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement