Skip to content

Commit

Permalink
Create trigger.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ibanezmatt13 committed Oct 13, 2013
1 parent 9df70e6 commit 650cb20
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions trigger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import requests
import json
import urllib2

bet_url = "http://google.co.uk"
print "checking altitude is more than 29500m...\n"
triggered = False # boolean to prevent duplicating bet
altitude_json_link = "http://habitat.habhub.org/habitat/_design/ept/_list/json/payload_telemetry/payload_time?include_docs=true&startkey=[%227830c4b51e021511a9bb8ff5dc1df89a%22]&endkey=[%227830c4b51e021511a9bb8ff5dc1df89a%22,[]]&fields=altitude" # altitude link from Habitat
trigger_json_link = "http://habitat.habhub.org/habitat/_design/ept/_list/json/payload_telemetry/payload_time?include_docs=true&startkey=[%227830c4b51e021511a9bb8ff5dc1df89a%22]&endkey=[%227830c4b51e021511a9bb8ff5dc1df89a%22,[]]&fields=trigger" # trigger link from Habitat

while True: # forever

r = requests.get(altitude_json_link) # get the JSON information
altitude = float(r.json()[-1]["altitude"]) # parse altitude to get a float
print "The altitude is: " + str(altitude) # print altitude

r = requests.get(trigger_json_link) # get the JSON information
trigger = str(r.json()[-1]["trigger"]) # parse trigger
print "The trigger is: " + trigger # print trigger

if altitude >= 29500 and trigger == "True" and triggered == False: # if altitude = 29500m and altitude hasn't already been reached
response = urllib2.urlopen(bet_url)
print response.info()



print "Bet Placed! Exiting..."
triggered = True
break

0 comments on commit 650cb20

Please sign in to comment.