How to use the twitterapi.Status.NewFromJsonDict function in TwitterAPI

To help you get started, we’ve selected a few TwitterAPI examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github idan / python-twitter / twitterapi.py View on Github external
parameters = {}
    if count:
      parameters['count'] = count
    if since:
      parameters['since'] = since
    if since_id:
      parameters['since_id'] = since_id
    if user:
      url = 'http://twitter.com/statuses/user_timeline/%s.json' % user
    elif not user and not self._username:
      raise TwitterError("User must be specified if API is not authenticated.")
    else:
      url = 'http://twitter.com/statuses/user_timeline.json'
    json = self._FetchUrl(url, parameters=parameters)
    data = simplejson.loads(json)
    return [Status.NewFromJsonDict(x) for x in data]
github idan / python-twitter / twitterapi.py View on Github external
Args:
      id: The numerical ID of the status you're trying to retrieve.

    Returns:
      A twitterapi.Status instance representing that status message
    '''
    try:
      if id:
        int(id)
    except:
      raise TwitterError("id must be an integer")
    url = 'http://twitter.com/statuses/show/%s.json' % id
    json = self._FetchUrl(url)
    data = simplejson.loads(json)
    return Status.NewFromJsonDict(data)
github idan / python-twitter / twitterapi.py View on Github external
  @staticmethod
  def NewFromJsonDict(data):
    '''Create a new instance based on a JSON dict.

    Args:
      data: A JSON dict, as converted from the JSON in the twitter API
    Returns:
      A twitterapi.User instance
    '''
    if 'status' in data:
      status = Status.NewFromJsonDict(data['status'])
    else:
      status = None
    return User(id=data.get('id', None),
                name=data.get('name', None),
                screen_name=data.get('screen_name', None),
                location=data.get('location', None),
                description=data.get('description', None),
                profile_image_url=data.get('profile_image_url', None),
                url=data.get('url', None),
                status=status)
github idan / python-twitter / twitterapi.py View on Github external
Args:
      since_id:
        Returns only public statuses with an ID greater than (that is,
        more recent than) the specified ID. [Optional]

    Returns:
      An sequence of twitterapi.Status instances, one for each message
    '''
    parameters = {}
    if since_id:
      parameters['since_id'] = since_id
    url = 'http://twitter.com/statuses/public_timeline.json'
    json = self._FetchUrl(url,  parameters=parameters)
    data = simplejson.loads(json)
    return [Status.NewFromJsonDict(x) for x in data]
github idan / python-twitter / twitterapi.py View on Github external
Args:
      text: The message text to be posted.  Must be less than 140 characters.

    Returns:
      A twitterapi.Status instance representing the message posted
    '''
    if not self._username:
      raise TwitterError("The twitterapi.Api instance must be authenticated.")
    if len(text) > 140:
      raise TwitterError("Text must be less than or equal to 140 characters.")
    url = 'http://twitter.com/statuses/update.json'
    data = {'status': text}
    json = self._FetchUrl(url, post_data=data)
    data = simplejson.loads(json)
    return Status.NewFromJsonDict(data)
github idan / python-twitter / twitterapi.py View on Github external
def CreateFavorite(self, status):
    '''Favorites the status specified in the status parameter as the authenticating user.
    Returns the favorite status when successful.

    The twitterapi.Api instance must be authenticated.

    Args:
      The twitterapi.Status instance to mark as a favorite.
    Returns:
      A twitterapi.Status instance representing the newly-marked favorite.
    '''
    url = 'http://twitter.com/favorites/create/%s.json' % status.id
    json = self._FetchUrl(url, post_data={})
    data = simplejson.loads(json)
    return Status.NewFromJsonDict(data)
github idan / python-twitter / twitterapi.py View on Github external
Args:
      id: The numerical ID of the status you're trying to destroy.

    Returns:
      A twitterapi.Status instance representing the destroyed status message
    '''
    try:
      if id:
        int(id)
    except:
      raise TwitterError("id must be an integer")
    url = 'http://twitter.com/statuses/destroy/%s.json' % id
    json = self._FetchUrl(url, post_data={})
    data = simplejson.loads(json)
    return Status.NewFromJsonDict(data)
github idan / python-twitter / twitterapi.py View on Github external
def DestroyFavorite(self, status):
    '''Un-favorites the status specified in the ID parameter as the authenticating user.
    Returns the un-favorited status in the requested format when successful.

    The twitterapi.Api instance must be authenticated.

    Args:
      The twitterapi.Status to unmark as a favorite.
    Returns:
      A twitterapi.Status instance representing the newly-unmarked favorite.
    '''
    url = 'http://twitter.com/favorites/destroy/%s.json' % status.id
    json = self._FetchUrl(url, post_data={})
    data = simplejson.loads(json)
    return Status.NewFromJsonDict(data)