Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import telepot
- import urllib2
- from bs4 import BeautifulSoup
- import time
- from selenium import webdriver
- from pprint import pprint
- import json
- user_states = [16841227,130979413,22020287]
- past_value = -1
- def handle(msg):
- chat_id = msg['chat']['id']
- user_states.append(chat_id)
- bot.sendMessage(chat_id,'Hello World')
- def sendNews():
- page_url = 'https://goo.gl/KLdxEW'
- page = urllib2.urlopen(page_url)
- soup = BeautifulSoup(page, 'html.parser')
- global past_value
- data = json.loads(str(soup))
- if((data['fields']['stato_periodo']['integerValue'] == '2') and (past_value != '2')):
- past_value = '2'
- for id in user_states:
- bot.sendMessage(id, "PROMO INIZIATA")
- if(data['fields']['stato_periodo']['integerValue'] == '1' and (past_value != '1')):
- past_value = '1'
- for id in user_states:
- bot.sendMessage(id, "Valore a 1")
- if(data['fields']['stato_periodo']['integerValue'] == '3' and (past_value != '3')):
- past_value = '3'
- for id in user_states:
- bot.sendMessage(id, "Promo terminata")
- TOKEN = ''
- bot = telepot.Bot(TOKEN)
- bot.message_loop(handle)
- print 'Listening ...'
- while 1:
- if(len(user_states)!=0):
- sendNews()
- time.sleep(30)
- else:
- time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement