Created
September 3, 2009 05:37
-
-
Save danmackinlay/180147 to your computer and use it in GitHub Desktop.
syndicates private friend-feed groups with read-only public feeds
This file contains 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
# −*− coding: UTF−8 −*− | |
""" | |
quick/dirty private feed exposer | |
http://friendfeed.com/api/documentation | |
http://www.dalkescientific.com/Python/PyRSS2Gen.html | |
http://code.google.com/p/httplib2/ | |
http://labix.org/python-dateutil | |
""" | |
import settings | |
from settings import FF_BASE_URL, FF_API_BASE_URL, FF_REMOTE_KEY, FF_FEED, FF_NICKNAME, FF_CONSUMER_SECRET, OUTPUT_CACHE_DIR, INPUT_CACHE_DIR | |
import httplib2 | |
import simplejson | |
import datetime | |
import PyRSS2Gen | |
from dateutil import parser | |
import re | |
import time | |
def strip_tags(value): | |
""" | |
Returns the given HTML with all tags stripped. | |
based on the django function of the same name | |
""" | |
return re.sub(r'<[^>]*?>', '', value) | |
h = httplib2.Http(INPUT_CACHE_DIR) | |
h.add_credentials(FF_NICKNAME, FF_REMOTE_KEY) | |
while True: | |
try: | |
resp, serialized = h.request(FF_API_BASE_URL + '/feed/' + FF_FEED, "GET") | |
except httplib2.HttpLib2Error: | |
continue | |
if resp['status']=='200': if resp['status']=='200': | |
content = simplejson.loads(serialized) | |
items=[] | |
for i in content['entries']: | |
if i.has_key('comments') and \ | |
len(i['comments']) and \ | |
i['comments'][0].has_key('body'): | |
description = i['comments'][0]['body'] | |
else: | |
description = i['body'] | |
title = strip_tags(i['body']).split(' - ')[0] | |
items.append(PyRSS2Gen.RSSItem( | |
link = i['url'], | |
guid = PyRSS2Gen.Guid(i['url']), | |
description = description, | |
pubDate = parser.parse(i['date']), | |
title = title, | |
author = i['from']['name'] | |
)) | |
rss = PyRSS2Gen.RSS2( | |
title = content['name'], | |
link = FF_BASE_URL + '/' + FF_FEED, | |
description = "friendfeed feed for %s" % content['name'], | |
lastBuildDate = datetime.datetime.utcnow(), | |
items = items | |
) | |
rss.write_xml(open(OUTPUT_CACHE_DIR+"/rss.xml", "w")) | |
time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment