Created
May 17, 2014 02:28
-
-
Save Maome/76cdc7b49eb0390d5337 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from googlevoice import Voice | |
import md5 | |
import urllib2 | |
from bs4 import BeautifulSoup | |
import pickle | |
import sqlite3 | |
debug = True | |
#setup hash | |
fail_silent = False | |
try: | |
f = open('/tmp/paxhash', 'r') | |
previous_hash = pickle.load(f) | |
f.close() | |
if debug: | |
print('previous hash loaded: ' + previous_hash) | |
except: | |
print('file read error, generating hash without check') | |
fail_silent = True | |
#get phone info | |
#load db | |
con = sqlite3.connect('test.db') | |
cur = con.cursor() | |
cur.execute('select distinct * from tbl_phones') | |
data = cur.fetchall() | |
phones = [] | |
for record in data: | |
phones.append(record[0]) | |
try: | |
paxurl = urllib2.urlopen('http://prime.paxsite.com/registration') | |
paxsite = paxurl.read() | |
paxsite_soup = BeautifulSoup(paxsite) | |
target_soup = paxsite_soup.find("div", {"id": "badgeAvailability"}) | |
time_soup = paxsite_soup.find("div", {"id": "countdown"}).find("h2") | |
hash_string = str(target_soup) + str(time_soup) | |
if debug: | |
print hash_string | |
target_md5 = md5.new(hash_string).hexdigest() | |
f = open('/tmp/paxhash', 'w') | |
pickle.dump(str(target_md5), f) | |
f.close() | |
#test for differences | |
hash_changed = previous_hash != target_md5 | |
except: | |
#on any error lets just say the hash changed | |
hash_changed = True | |
if fail_silent: | |
sys.exit() | |
if debug: | |
print('hash change is ' + str(hash_changed)) | |
if hash_changed: | |
voice = Voice() | |
voice.login('myemail@gmail.com', 'password') | |
for phoneNumber in phones: | |
message = 'http://prime.paxsite.com/registration has been updated!' | |
if debug: | |
print('sending message to: ' + phoneNumber) | |
voice.send_sms(phoneNumber, message) | |
#do google callout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment