Skip to content

Instantly share code, notes, and snippets.

@tsaylor
Forked from orblivion/gist:75200
Created March 19, 2009 01:08
Show Gist options
  • Save tsaylor/81524 to your computer and use it in GitHub Desktop.
Save tsaylor/81524 to your computer and use it in GitHub Desktop.
import re, datetime
import twitter, PyRSS2Gen
def getURLs(text):
url=unicode(r"((http|ftp)://)?(((([\d]+\.)+){3}[\d]+(/[\w./]+)?)|([a-z]\w*((\.\w+)+){2,})([/][\w.~]*)*)")
return [a.group() for a in re.finditer(url,text)]
def mkFeedItem(url):
return PyRSS2Gen.RSSItem(
title = "Twitter Link",
link = url,
description = "Some shit from Twitter",
guid = PyRSS2Gen.Guid(url),
pubDate = datetime.datetime(2003, 9, 6, 21, 31)) # get
the right date/time from python-twitter
def mkFeed(urls):
rss = PyRSS2Gen.RSS2(
title = "Twitter Links",
link = "www.twitter.com",
description = "Your friends' stupid links",
items = [mkFeedItem(u) for u in urls],
lastBuildDate = datetime.datetime.now() )
rss.write_xml(open("twitterlinkfeed.xml", "w"))
api = twitter.Api(username="tsaylor", password="imsecretlyinlovewithkevin")
statuses = api.GetFriendsTimeline("tsaylor")
alltext = [s.text for s in statuses]
# get one list of URLs, even if there are multiple URLs in some posts
allurls = []
for t in alltext:
for url in getURLs(t):
allurls.append (url)
mkFeed(allurls)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment