Created
November 19, 2013 23:09
-
-
Save kimondo/7554249 to your computer and use it in GitHub Desktop.
Raspberry Pi Pi-Lite web counter - grabs some stats off the wordpress stats API and then sends them to the serial port to be picked up by an arduino based LED display (ciseco.co.uk Pi-Lite or wharfe-education.com BelleVue)
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 serial | |
import time | |
import urllib2 | |
from BeautifulSoup import BeautifulSoup | |
# Configure Pi serial port | |
s = serial.Serial() | |
s.baudrate = 9600 | |
s.timeout = 0 | |
s.port = "/dev/ttyAMA0" | |
#grab the stats | |
#replace yourAPIkey with your wordpress API from this page https://apikey.wordpress.com/ | |
#replace your blog address | |
page = urllib2.urlopen("http://stats.wordpress.com/csv.php?api_key=yourAPIkey&blog_uri=www.yourblogaddress.com&days=-1&summarize") | |
#edit the &days=-1 part for different stats: | |
# days=1 is the number of visits today | |
# days=30 is the number for the last 30 days | |
# months=1 is the number for the last month | |
soup = BeautifulSoup(page) | |
print soup | |
#turn it into a string | |
count=str(soup) | |
#remove the bits we don't need | |
count = count.replace("views",""); | |
count = count.replace('"',""); | |
print count | |
try: | |
# Open serial port | |
s.open() | |
except serial.SerialException, e: | |
# There was an error | |
sys.stderr.write("could not open port %r: %s\n" % (port, e)) | |
sys.exit(1) | |
print "Serial port ready" | |
# Clear display | |
s.write("$$$ALL,OFF\r") | |
# Send count to the serial port | |
# the Pi-Lite requires the loop to keep displaying the text, the http://wharfe-education.com LED counter doesn't require it | |
while True | |
s.write(count) | |
time.sleep(12) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment