Colorize Your Election Party

blue_red
[Eric] has put together a simple python script to scrape election results from CNN.com. It uses urllib2 to return the popular and electoral votes for each party and throws an ElectionWon exception when CNN calls the race. He’s planning on hooking this to DMX controlled RGB LED lighting that will shift to either blue or red as the night progresses. It’s a great starting point if you want to pull off something similar.

You may remember [Eric] for building the IKEA MAME table and the TRS-80 wireless terminal.

[photo: skenmy]

UPDATE: [Garrett] of macetech is putting the finishing touches on his version which uses 32 ShiftBrite modules and 2 4-digit displays controlled by a CuBLOC.

19 thoughts on “Colorize Your Election Party

  1. @tricky

    radioshack wouldn’t help you too much with DMX lighting fixtures. you happen to have one though, ranging from a $70 chauvet PAR to a $2000 martin strip light, the DMX protocol is pretty simple as I understand it. Should be easy to fake up with a uc of some sort.

  2. This is PERFECT for any election party. Imagine watching the election on TV and having all the walls around you shift colors like that as your guests yell at it for being blue or red when they want it red or blue.

  3. You can do this tomorrow if you happen to live near a Guitar Center. Go in a buy a few LED par cans. Grab some XLR cables. Buy a DMX controller. I’m using a ENTTEC DMX USB PRO, which might not be available at Guitar Center, but an alternative certainly is.

    Though the DMX protocol is quite simple, it does have some tricky timing. I’d caution against trying to whip it up from scratch given the fact that it can be done on a computer quite cheaply.

    I was actually just integrating the code I posted with the DMX code (from a previous project) and I’ll update the blog entry with the final code shortly.

  4. I’m building one of these right now. I’ve got his code running, with some modifications to send the data to a Bluetooth/serial module using rfcomm. It’ll have a red/blue bar graph and large numerical displays with the count at either end. It’s going to look like an 80’s cartoon battle….

  5. I’m parsing the data now, but the tough part is I’m not sure what the format of the popular vote variable will be. Maybe it’s a plain number, maybe it’s thousands-separated, etc. I guess I will have to tune the code a little bit tomorrow. But the physical construction is next….

  6. Yay, it’s working! Okay: 32 RGB ShiftBrite modules in a row, running off a Cubloc CB405, receiving data over a Bluetooth connection from a Linux box running in a closet. That box is running a modified version of the CNN scraper. I’m using the 32 LEDs as a bar graph, and I have two red 2″ 4-digit 7 segment displays showing the actual electoral counts. Just going to tack this all to a plank tomorrow, it’s ready! Pics: http://www.flickr.com/photos/macetech/3001651751/

  7. Grab a couple of super bright red led’s and a couple of super bright BLue LED’s

    write a simple pic project to modulate them and get data via rs232. use a pc to collect the data and send the numbers to the pic.

    same thing in 20 minutes and far less money spent.

    will you fill a room full of light? no, but then the DMX lighting setup will run several hundred anyways.

  8. I added a touch of code to the python scrape to convert the normalized values into hex color codes and send that over serial to my arduino.

    I’d say it works well, but we’re still at 0,0 :)

    but hey, no dmx, just arduino and a few red and blue leds.

  9. I modified their code to make a live election ticker.
    import urllib2
    import re
    import os
    import time

    def ElectionWon(winner):
    while 1:print winner, ” WIN!!!!!!”

    class CNN(object):
    def __init__(self):
    self.url = “http://www.cnn.com/ELECTION/2008/results/president/”

    def get(self):
    “””return the electoral balance
    (dpopular, delectoral), (rpopular, relectoral)
    “””
    u = urllib2.urlopen(self.url)
    for line in u.readlines():
    res = re.search(r’var CNN_NData=(.*?);’, line)
    if res is not None:
    data = res.group(1)
    data = data.replace(“true”, “True”)
    data = data.replace(“false”, “False”)
    data = eval(data)

    d,r = None, None
    for candidate in data[‘P’][‘candidates’]:
    if candidate[‘party’] == ‘D’:
    d = candidate[‘votes’], candidate[‘evotes’]
    if candidate[‘winner’]:
    ElectionWon(“DEMOCRATS”)
    elif candidate[‘party’] == ‘R’:
    r = candidate[‘votes’], candidate[‘evotes’]
    if candidate[‘winner’]:
    ElectionWon(“REPUBLICANS”)
    if d[1] > r[1]: leader = “<<<<< d[1]: leader = “>>>>>>”
    if d == r: leader = “——”
    print “Democrats Popular:”,d[0],” Democrats Electoral:”,d[1],leader,” Republicans Popular:”,r[0],” Republicans Electoral:”,r[1]
    return 0

    if __name__==’__main__’:
    cnn = CNN()
    os.system(“clear”)
    while 1:
    cnn.get()
    time.sleep(2)
    os.system(“clear”)
    “””DOS users should replace ‘clear’ with ‘cls'”””

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.