Skip to content

Instantly share code, notes, and snippets.

@tomconte
Created January 9, 2013 19:56
Show Gist options
  • Save tomconte/4496283 to your computer and use it in GitHub Desktop.
Save tomconte/4496283 to your computer and use it in GitHub Desktop.
This is a very basic Python script that will let you poll ThingM's IFTT event service. You need to change the "IFTT key" in the URL, and use that same key in your IFTT blink(1) channel. I think any 16-character string will work but you should generate your own unique value, possibly including the blink(1) serial number (blink1-tool --list). The …
#!/usr/bin/python
import urllib2
import json
import time
import calendar
import subprocess
url = 'http://api.thingm.com/blink1/events/01234567DEADC0DE'
last_time = 0
while True:
req = urllib2.Request(url)
res = urllib2.urlopen(req)
data = res.read()
ev = json.loads(data)
if ev['event_count'] > 0:
print 'events to process'
for e in ev['events']:
print e
if int(e['date']) > last_time:
print 'trigger: ' + e['name']
subprocess.call(['./'+e['name']+'.sh'])
last_time = calendar.timegm(time.gmtime())
time.sleep(30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment