Created
May 3, 2013 03:15
-
-
Save imrehg/5506959 to your computer and use it in GitHub Desktop.
Facebook likes from web sent to wireless Arduino
This file contains hidden or 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 urllib2 # for requests | |
import simplejson # for JSON conversion | |
import sys # for command line arguments | |
import time # for delays | |
# Get the page FB ID string from 1st command line argument | |
pagename = sys.argv[1] | |
# Download the page data into python dict | |
url = "http://graph.facebook.com/%s" %(pagename) | |
request = urllib2.Request(url) | |
opener = urllib2.build_opener() | |
f = opener.open(request) | |
data = simplejson.load(f) | |
# Display results | |
print "%s has %d likes" %(data['name'], data['likes']) | |
# Send like data to wireless Arduino | |
displayURL = 'http://192.168.1.80/cgi-bin/web2ser?' | |
for digit in str(data['likes']): | |
digitrequest = urllib2.Request("%s?%s" %(displayURL, digit)) | |
response = urllib2.urlopen(digitrequest) | |
time.sleep(1) # sleep 1s between digits | |
print("-> All done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment