Created
December 7, 2012 01:11
-
-
Save irl/4229914 to your computer and use it in GitHub Desktop.
Reading SDF Chatter
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 | |
import re | |
from xml.dom.minidom import parseString | |
class GUIDS: | |
guids = [] | |
def __init__(self): | |
f = open("/meta/i/irl/.chatterguids") | |
c = f.read().replace("\n", "") | |
f.close() | |
self.guids = c.split(";") | |
class Statuses: | |
items = [] | |
def getText(self, nodelist): | |
rc = [] | |
for node in nodelist: | |
if node.nodeType == node.TEXT_NODE: | |
rc.append(node.data) | |
xtxt = ''.join(rc) | |
return re.sub("<[^>]+>", "", xtxt) | |
def __init__(self, user): | |
url = urllib2.urlopen("https://wm.sdf.org/status/api/statuses/user_timeline/" + user + ".rss") | |
rss = url.read() | |
url.close() | |
dom = parseString(rss) | |
for item in dom.getElementsByTagName("item"): | |
i = {} | |
i["pubDate"] = self.getText(item.getElementsByTagName("pubDate")[0].childNodes) | |
i["guid"] = self.getText(item.getElementsByTagName("guid")[0].childNodes) | |
i["description"] = self.getText(item.getElementsByTagName("description")[0].childNodes) | |
self.items.append(i) | |
def getNewItems(self): | |
g = GUIDS().guids | |
n = [] | |
for i in self.items: | |
if i["guid"] not in g: | |
n.append(i) | |
return n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment