Skip to content

Instantly share code, notes, and snippets.

@irl
Created December 7, 2012 01:11
Show Gist options
  • Save irl/4229914 to your computer and use it in GitHub Desktop.
Save irl/4229914 to your computer and use it in GitHub Desktop.
Reading SDF Chatter
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