User:Dave Young/Prototyping 5.1

From XPUB & Lens-Based wiki

Remixing an RSS Feed


For this exercise I have remixed the "Top Headlines" rss feeds of two news agencies with opposing agendas - FOX and CNN. In the lead up to the presidential elections in the US next year, I noticed increasingly biased reporting from both agencies (both were also accused of strategic editorialising in the lead up to the last election in 2008). With the recent controversies surrounding Rick Perry, Newt Gingrich, the Occupy Movement, Obama stating that the US army would pull out of Iraq etc, I am curious about how each agency will spin the headlines in order to encourage a particular public viewpoint.

The piece is intended to remain as objective as possible and let the website visitor to interpret the headlines as they wish. CNN appears in red and Fox in dark blue (colours taken from their logos), and only the headlines + their date of publishing are displayed on the rss feed. By clicking the headline, you are linked to the story.



Technically the piece is quite simple, but was a good exercise in learning about lxml in python :) It consists of two components: a python script that reads the rss feeds triggered by a cronjob every half hour, and dumps the results into a .txt file. The second component is a cgi-script that loads the data from the .txt file and prints it to the webpage.

# Get RSS xml data from feeds and write to feed.txt
# h6

import lxml.etree

file = open('feed.txt', 'w')

cnn = ""
fox = ""

def getFeed(feed):
        doc = lxml.etree.parse(feed)
        entries = []
        index = 0
        maxResults = 10
        # check how many items are in the rss
        # print len(doc.xpath("//item")), "items"

        #return headline + link
        for item in doc.xpath("//item"):
                        title = item.xpath(".//title/text()")[0]
                        link = item.xpath(".//link/text()")[0]
                        date = item.xpath(".//pubDate/text()")[0]
                        entries = title+'\t'+link+'\t'+date+'\n'

# Reads feed data from feed.txt
# feed.txt = cnn[[title, link, date],...],fox[[...]...]
# h6

file = open('feed.txt','r')
file =
xline = []

entry = []

cnn = ""
fox = ""

# split feed.txt into cnn and fox
for line in file.splitlines():
        line = filter(None, line)
        element = line.split('\t')
        title = element[0]
        link = '"'+element[1]+'"'
        date = element[2]
                cnn += "<a class='cnn' href="+element[1]+">"+element[0]+"</a>"+"<div class='info'>"+element[2]+"</div>"
                fox += "<a class='fox' href="+element[1]+">"+element[0]+"</a>"+"<div class='info'>"+element[2]+"</div>"

print """Content-type: text/html\n\n\n"""

print """<html>
<style type="text/css">
body {{ font-family: Sans; font-size: 20px; margin: 0 auto; width: 1024px;}}
h1.cnn{{ font-size: 48px; font-family: Arial,Helvetica,Utkal,sans-serif; color: #D32026; padding: 0px;}}{{ font-size: 48px; font-family: Arial, sans-serif; color: #183A52; padding: 0px;}}
#left{{ float: left; width: 490px; padding: 0px; margin: 10px 0px;}}
#right{{ float: right; width: 490px; padding: 10px;}}
a{{ padding-left: 5px; padding-right: 5px; text-decoration: none;}}
a.cnn:link{{ background: #D32026; color: #FFF;}}
a.cnn:visited{{ color: #FFF;}}
a.cnn:hover{{ background: #000; color: #FFF;}}{{ background: #183A52; color: #FFF;}}{{ color: #FFF;}}
.info{{ font-size: 10px; font-style: italic; padding-bottom: 20px; padding-top: 5px;}}

<div id="left">
<h1 class="cnn">CNN</h1>

<div id="right">
<h1 class="fox">FOX</h1>

""".format(cnn, fox)