Commits

Dan Carroll committed 68557a0

Add a Twitter search provider, and rename TwitterProvider to TwitterUserProvider to distinguish

  • Participants
  • Parent commits ce96490

Comments (0)

Files changed (4)

 Repository version
 ------------------
 
-* BACKWARDS INCOMPATIBLE CHANGE:
+* Added TwitterSearchProvider to allow syncing the results of a Twitter
+  search query
 
-* Added additional
+* BACKWARDS INCOMPATIBLE CHANGE: Renamed TwitterProvider to TwitterUserProvider
+  to distinguish it from the new TwitterSearchProvider
 
 
 Version 0.1.2, 8 Feb 2011
 
     ACTIVITYSYNC_PROVIDERS = (
         'activitysync.providers.googlereader.GoogleReaderProvider',
-        'activitysync.providers.twitterprovider.TwitterProvider',
+        'activitysync.providers.twitterprovider.TwitterUserProvider',
+        'activitysync.providers.twitterprovider.TwitterSearchProvider',
         'activitysync.providers.redditprovider.RedditProvider',
     )
 
 - Add provider settings to settings.py (dependent on which providers are added).
   Settings required for built-in providers are::
 
-    TWITTER_USERNAME        = ''
-    REDDIT_USERNAME         = ''
+    TWITTER_USERNAME        = '' # Username to use for TwitterUserProvider
+    TWITTER_SEARCHTERM      = '' # Search term to use for TwitterSearchProvider
+    REDDIT_USERNAME         = '' # Username to use for RedditProvider
     GOOGLEREADER_SHARED_RSS = '' # URL of your shared items RSS
     GOOGLEREADER_PUBLIC_URL = '' # URL to public page
 

File activitysync/providers/twitterprovider.py

 import datetime
 import twitter as TwitterLibrary
 
-class TwitterProvider(ActivityProvider):
+class TwitterUserProvider(ActivityProvider):
     """
     Provider for accessing Twitter status updates for one user.
     """
         print 'Attempting to obtain Twitter items'
         api = TwitterLibrary.Api()
         username = settings.TWITTER_USERNAME
+        print ' Username: %s' % 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
+            author = status.user.name or ''
                 
             date_published = datetime.datetime.fromtimestamp(status.created_at_in_seconds)
                  
     def sourceid(self):
         return 'twitter'
 
+
+class TwitterSearchProvider(ActivityProvider):
+    """
+    Provider for accessing Twitter status updates from a search query.
+    """
+
+    def get_activity(self):
+        item_list = []
+
+        print 'Attempting to obtain Twitter items'
+        api = TwitterLibrary.Api()
+        query = settings.TWITTER_SEARCHTERM
+        print ' Search term: %s' % query
+        statuses = api.GetSearch(term=query, per_page=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 or ''
+            username = status.user.screen_name
+
+            date_published = datetime.datetime.fromtimestamp(status.created_at_in_seconds)
+
+            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/search?q=%s' % settings.TWITTER_SEARCHTERM
+
+    def sourceid(self):
+        return 'twitter'
+

File examples/activitydisplay/settings.py

 )
 
 ACTIVITYSYNC_PROVIDERS = (
-    'activitysync.providers.twitterprovider.TwitterProvider',
+    'activitysync.providers.twitterprovider.TwitterUserProvider',
+    'activitysync.providers.twitterprovider.TwitterSearchProvider',
     # 'activitysync.providers.googlereader.GoogleReaderProvider',
     # 'activitysync.providers.redditprovider.RedditProvider',
 )
 
 TWITTER_USERNAME = 'twitter'
+TWITTER_SEARCHTERM = 'django'
 # REDDIT_USERNAME = ''
 # GOOGLEREADER_SHARED_RSS = ''
 # GOOGLEREADER_PUBLIC_URL = ''