Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 ( Pi-Lite or BelleVue)
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
#replace your blog address
page = urllib2.urlopen("")
#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
#remove the bits we don't need
count = count.replace("views","");
count = count.replace('"',"");
print count
# Open serial port
except serial.SerialException, e:
# There was an error
sys.stderr.write("could not open port %r: %s\n" % (port, e))
print "Serial port ready"
# Clear display
# Send count to the serial port
# the Pi-Lite requires the loop to keep displaying the text, the LED counter doesn't require it
while True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment