Commits

Dan Carroll committed 9abf1aa

Add Twitter and Reddit activity providers. Remove hard coded user information from Google Reader provider.

Comments (0)

Files changed (5)

mysite/activitysync/providers/googlereader.py

         item_list = []
 
         print 'Attempting to parse Google Reader feed'
-        parsed_feed = feedparser.parse("http://www.google.com/reader/public/atom/user%2F10780706687522073033%2Fstate%2Fcom.google%2Fbroadcast")
+        parsed_feed = feedparser.parse(settings.GOOGLEREADER_SHARED_RSS)
     
         for entry in parsed_feed.entries:
             title = entry.title.encode(parsed_feed.encoding, "xmlcharrefreplace")
         return 'Shared'
 
     def link(self):
-        return 'http://www.google.com/reader/shared/dancarroll'
+        return settings.GOOGLEREADER_PUBLIC_URL
 
     def sourceid(self):
-        return 'GR'
+        return 'googlereader'
 

mysite/activitysync/providers/redditprovider.py

+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.REDDIT_USERNAME
+        parsed_feed = feedparser.parse("http://www.reddit.com/user/%s/liked/.rss" % username)
+
+        for entry in parsed_feed.entries:
+            title = entry.title.encode(parsed_feed.encoding, "xmlcharrefreplace")
+            guid = entry.get("id", entry.link).encode(parsed_feed.encoding, "xmlcharrefreplace")
+            link = entry.link.encode(parsed_feed.encoding, "xmlcharrefreplace")
+
+            if not guid:
+                guid = link
+
+            if entry.has_key('author'):
+                author = entry.author.encode(parsed_feed.encoding, "xmlcharrefreplace")
+            else:
+                author = u''
+
+            try:
+                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)
+                else:
+                    date_published = datetime.datetime.now()
+            except TypeError:
+                date_published = datetime.datetime.now()
+                    
+            activity_info = ActivityInfo(title=title, link=link, pub_date=date_published, guid=guid, username=username, author=author)
+            item_list.append(activity_info)
+
+        return item_list
+
+
+    def name(self):
+        return 'Reddit'
+
+    def prefix(self):
+        return 'Liked'
+
+    def link(self):
+        return 'http://www.reddit.com/user/%s/' % settings.REDDIT_USERNAME
+
+    def sourceid(self):
+        return 'reddit'
+

mysite/activitysync/providers/twitterprovider.py

+from django.conf import settings
+from activitysync.providers import ActivityProvider, ActivityInfo
+
+import time
+import datetime
+import twitter as TwitterLibrary
+
+class TwitterProvider(ActivityProvider):
+    """
+    Provider for accessing Twitter status updates for one user.
+    """
+    
+    def get_activity(self):
+        item_list = []
+
+        print 'Attempting to obtain Twitter items'
+        api = TwitterLibrary.Api()
+        username = settings.TWITTER_USERNAME
+        statuses = api.GetUserTimeline(username, count=50)
+
+        for status in statuses:
+            title = status.text
+            guid = "twitter:%s" % status.id
+            link = "http://twitter.com/%s/statuses/%s" % (status.user.screen_name, status.id)
+            author = status.user.name
+                
+            date_published = datetime.datetime.fromtimestamp(status.created_at_in_seconds)
+                 
+            # Don't show @replies
+            if not status.in_reply_to_user_id:
+                activity_info = ActivityInfo(title=title, link=link, pub_date=date_published, guid=guid, username=username, author=author)
+                item_list.append(activity_info)
+
+        return item_list
+
+
+    def name(self):
+        return 'Twitter'
+
+    def prefix(self):
+        return ''
+
+    def link(self):
+        return 'http://twitter.com/%s' % settings.TWITTER_USERNAME
+
+    def sourceid(self):
+        return 'twitter'
+

mysite/deploy.py.template

 DISQUS_WEBSITE_SHORTNAME = ''
 
 GOOGLE_ANALYTICS_CODE = ''
+
+TWITTER_USERNAME = ''
+REDDIT_USERNAME = ''
+GOOGLEREADER_SHARED_RSS = ''
+GOOGLEREADER_PUBLIC_URL = ''
+

mysite/settings.py

 import os
 import deploy
 
-ACTIVITYSYNC_PROVIDERS = (
-    'activitysync.providers.googlereader.GoogleReaderProvider',
-)
-
 DEBUG = deploy.DEBUG
 TEMPLATE_DEBUG = DEBUG
 
     'south',
 )
 
+# Activity sync settings
+ACTIVITYSYNC_PROVIDERS = (
+    'activitysync.providers.googlereader.GoogleReaderProvider',
+    'activitysync.providers.twitterprovider.TwitterProvider',
+    'activitysync.providers.redditprovider.RedditProvider',
+)
+
+TWITTER_USERNAME = deploy.TWITTER_USERNAME
+REDDIT_USERNAME = deploy.REDDIT_USERNAME
+GOOGLEREADER_SHARED_RSS = deploy.GOOGLEREADER_SHARED_RSS
+GOOGLEREADER_PUBLIC_URL = deploy.GOOGLEREADER_PUBLIC_URL
+
 XMLRPC_METHODS = (
     # We list methods to be exposed in the form (<method path>, <xml-rpc name>,)
     ('mysite.metaweblog.metaweblog.get_post', 'test',),
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 ProjectModifiedEvent.java.
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.