Skip to content

Instantly share code, notes, and snippets.

@tuxmartin
Created September 23, 2015 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxmartin/5f5818377eec5a736461 to your computer and use it in GitHub Desktop.
Save tuxmartin/5f5818377eec5a736461 to your computer and use it in GitHub Desktop.
Angee Kickstarter Notification
# http://raspi.tv/2014/programming-a-kickstarter-tracker-in-python-part-1
from urllib2 import Request, urlopen, URLError
from time import sleep
import subprocess
someurl = 'https://www.kickstarter.com/projects/tomtu/angee-the-first-truly-autonomous-home-security-sys'
old_percent= 0.0
def send_message(title, message):
command = 'notify-send -u normal -t 15000 "' + title + '" "' + message + '"'
print command
subprocess.Popen(command, stderr=None, shell=True)
while True:
req = Request(someurl)
try:
response = urlopen(req)
except URLError as e:
if hasattr(e, 'reason'):
print 'Chyba'
else:
the_page = response.readlines() # read each line of the html file
for line in the_page: # iterate through the lines
if 'data-goal' in line:
words = line.split(" ") # split line into 'words'
for word in words: # iterate through 'words'
if 'data-goal' in word:
target = word.split('"') # split word at " character
# make 2nd element a float
print 'Target: %.2f' % float(target[1]) # then truncate to 2 d.p.
if 'data-percent-raised' in word:
percent = word.split('"')
print 'Percentage raised: %.2f' % (float(percent[1]) * 100)
if 'data-pledged' in word:
amount_raised = word.split('"')
print 'Total so far: %.2f' % float(amount_raised[1])
print ' ' # stick a blank line on the end
if (float(percent[1]) * 100) > old_percent:
old_percent = (float(percent[1]) * 100)
target = 'Target: $ %.0f' % float(target[1])
percent = 'Percentage raised: %.2f %%' % (float(percent[1]) * 100)
total = 'Total so far: $ %.2f' % float(amount_raised[1])
send_message("Angee Kickstarter",
target + '\n' + total + '\n\n' + percent)
break # break out of th
sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment