xitiomet / python-twitter

fork of python-twitter

Mostly the same, but i added support for Mentions http://apiwiki.twitter.com/Twitter-REST-API-Met...

Clone this repository (size: 393.3 KB): HTTPS / SSH
$ hg clone http://hg.openstatic.org/python-twitter
commit 119: 42a0465d458f
parent 118: 19260f87c32a
branch: dclinton
Cleanup whitespace
dcli...@b35c0ba3-1128-0410-9219-0b39014e361d
15 months ago

Changed (Δ44 bytes):

raw changeset »

twitter.py (25 lines added, 25 lines removed)

twitter_test.py (2 lines added, 2 lines removed)

Up to file-list twitter.py:

@@ -46,7 +46,7 @@ CHARACTER_LIMIT = 140
46
46
47
47
class TwitterError(Exception):
48
48
  '''Base class for Twitter errors'''
49
  
49
50
50
  @property
51
51
  def message(self):
52
52
    '''Returns the first argument used to construct this error.'''
@@ -122,8 +122,8 @@ def ComputeRelativeCreatedAt(status, now
122
122
123
123
  Args:
124
124
    status: A status instance
125
    now: 
126
      The current time, if the client choses to set it.  Defaults 
125
    now:
126
      The current time, if the client choses to set it.  Defaults
127
127
      to the wall clock time.
128
128
  Returns:
129
129
    A human readable string representing the posting time
@@ -360,7 +360,7 @@ class Api(object):
360
360
  def GetFriendsTimeline(self,
361
361
                         user=None,
362
362
                         count=None,
363
                         since=None, 
363
                         since=None,
364
364
                         since_id=None):
365
365
    '''Fetch the sequence of Status messages for a user's friends
366
366
@@ -371,7 +371,7 @@ class Api(object):
371
371
        Specifies the ID or screen name of the user for whom to return
372
372
        the friends_timeline.  If unspecified, the username and password
373
373
        must be set in the twitter.Api instance.  [Optional]
374
      count: 
374
      count:
375
375
        Specifies the number of statuses to retrieve. May not be
376
376
        greater than 200. [Optional]
377
377
      since:
@@ -561,13 +561,13 @@ class Api(object):
561
561
    results.append(self.PostUpdate(lines[-1], **kwargs))
562
562
    return results
563
563
564
  def GetReplies(self, since=None, since_id=None, page=None): 
564
  def GetReplies(self, since=None, since_id=None, page=None):
565
565
    '''Get a sequence of status messages representing the 20 most recent
566
566
    replies (status updates prefixed with @username) to the authenticating
567
567
    user.
568
568
569
569
    Args:
570
      page: 
570
      page:
571
571
      since:
572
572
        Narrows the returned results to just those statuses created
573
573
        after the specified HTTP-formatted date. [optional]
@@ -608,7 +608,7 @@ class Api(object):
608
608
    if not self._username:
609
609
      raise TwitterError("twitter.Api instance must be authenticated")
610
610
    if user:
611
      url = 'http://twitter.com/statuses/friends/%s.json' % user 
611
      url = 'http://twitter.com/statuses/friends/%s.json' % user
612
612
    else:
613
613
      url = 'http://twitter.com/statuses/friends.json'
614
614
    parameters = {}
@@ -694,7 +694,7 @@ class Api(object):
694
694
    if since_id:
695
695
      parameters['since_id'] = since_id
696
696
    if page:
697
      parameters['page'] = page 
697
      parameters['page'] = page
698
698
    json = self._FetchUrl(url, parameters=parameters)
699
699
    data = simplejson.loads(json)
700
700
    self._CheckForTwitterError(data)
@@ -820,30 +820,30 @@ class Api(object):
820
820
    self._CheckForTwitterError(data)
821
821
    return NewUserFromJsonDict(data)
822
822
823
  def Search(self, 
824
             query, 
825
             lang=None, 
826
             rpp=None, 
827
             page=None, 
828
             since_id=None, 
829
             geocode=None, 
823
  def Search(self,
824
             query,
825
             lang=None,
826
             rpp=None,
827
             page=None,
828
             since_id=None,
829
             geocode=None,
830
830
             show_user=None):
831
831
    '''Returns tweets that match a specified query.
832
832
833
833
    Args:
834
834
      query: The search query string, must be less than 140 characters
835
      lang: 
836
        Restricts tweets to the given language, given by an ISO 639-1 
835
      lang:
836
        Restricts tweets to the given language, given by an ISO 639-1
837
837
        code. [Optional]
838
838
      rpp:
839
839
        The number of tweets to return per page, up to a max of 100. [Optional]
840
      page: 
840
      page:
841
841
        The page number (starting at 1) to return, up to a max of
842
842
        roughly 1500 results (based on rpp * page. Note: there are
843
843
        pagination limits. [Optional]
844
      since_id: 
844
      since_id:
845
845
        Returns tweets with status ids greater than the given id. [Optional]
846
      geocode:       
846
      geocode:
847
847
        Returns tweets by users located within a given radius of the
848
848
        given latitude/longitude, where the user's location is taken
849
849
        from their Twitter profile. The parameter value is specified
@@ -860,7 +860,7 @@ class Api(object):
860
860
      A Results instance representing the search results
861
861
    '''
862
862
    url = 'http://search.twitter.com/search.json'
863
    
863
864
864
    parameters = {'q': query}
865
865
    if len(query) > 140:
866
866
      raise TwitterError('query must be <= 140 characters')
@@ -1088,10 +1088,10 @@ class Api(object):
1088
1088
1089
1089
    Args:
1090
1090
      url: The URL to retrieve
1091
      post_data: 
1091
      post_data:
1092
1092
        A dict of (str, unicode) key/value pairs.  If set, POST will be used.
1093
1093
      parameters:
1094
        A dict whose key/value pairs should encoded and added 
1094
        A dict whose key/value pairs should encoded and added
1095
1095
        to the query string. [OPTIONAL]
1096
1096
      no_cache: If true, overrides the cache on the current request
1097
1097
@@ -1221,7 +1221,7 @@ class _FileCache(object):
1221
1221
        hashed_key = md5(key).hexdigest()
1222
1222
    except TypeError:
1223
1223
        hashed_key = md5.new(key).hexdigest()
1224
        
1224
1225
1225
    return os.path.join(self._root_directory,
1226
1226
                        self._GetPrefix(hashed_key),
1227
1227
                        hashed_key)

Up to file-list twitter_test.py:

@@ -69,7 +69,7 @@ class StatusTest(unittest.TestCase):
69
69
    status.created_at = 'Fri Jan 26 23:17:14 +0000 2007'
70
70
    self.assertEqual('Fri Jan 26 23:17:14 +0000 2007', status.created_at)
71
71
    now = created_at + 10
72
    self.assertEqual('about 10 seconds ago', 
72
    self.assertEqual('about 10 seconds ago',
73
73
                     twitter.ComputeRelativeCreatedAt(status, now))
74
74
    status.user.CopyFrom(self._GetSampleUser())
75
75
    self.assertEqual(718443, status.user.id)
@@ -238,7 +238,7 @@ class ResultsTest(unittest.TestCase):
238
238
    results = twitter.NewResultsFromJsonDict(data)
239
239
    self.assertEqual(0.016569, results.completed_in)
240
240
    self.assertEqual(1818791702, results.max_id)
241
    self.assertEqual('?page=2&max_id=1818791702&rpp=2&q=twitter', 
241
    self.assertEqual('?page=2&max_id=1818791702&rpp=2&q=twitter',
242
242
                     results.next_page)
243
243
    self.assertEqual(1, results.page)
244
244
    self.assertEqual('twitter', results.query)