django-activitysync / activitysync / providers /

from django.conf import settings
from activitysync.providers import ActivityProvider, ActivityInfo

import time
import datetime
import feedparser

class RedditProvider(ActivityProvider):
    Provider for accessing liked Reddit items for one user.
    def get_activity(self):
        item_list = []

        print 'Attempting to parse Reddit feed'
        username = settings.ACTIVITYSYNC_SETTINGS['REDDIT_USERNAME']
        parsed_feed = feedparser.parse("" % username)

        for entry in parsed_feed.entries:
            title = entry.title.encode(parsed_feed.encoding, "xmlcharrefreplace")
            guid = entry.get("id",, "xmlcharrefreplace")
            link =, "xmlcharrefreplace")

            if not guid:
                guid = link

            if entry.has_key('author'):
                author =, "xmlcharrefreplace")
                author = u''

                if entry.has_key('published_parsed'):
                    date_published = datetime.datetime.fromtimestamp(time.mktime(entry.published_parsed) - time.timezone)
                elif entry.has_key('updated_parsed'):
                    date_published = datetime.datetime.fromtimestamp(time.mktime(entry.updated_parsed) - time.timezone)
                elif entry.has_key('modified_parsed'):
                    date_published = datetime.datetime.fromtimestamp(time.mktime(entry.modified_parsed) - time.timezone)
                    date_published =
            except TypeError:
                date_published =
            activity_info = ActivityInfo(title=title, link=link, pub_date=date_published, guid=guid, username=username, author=author)

        return item_list

    def name(self):
        return 'Reddit'

    def prefix(self):
        return 'Liked'

    def link(self):
        return ('' %

    def sourceid(self):
        return 'reddit'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.