magalbraith / python-twitter

Automatically exported from code.google.com/p/python-twitter
Apache License 2.0
0 stars 0 forks source link

geotagging support in Api::PostUpdate() #107

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi there,

I have added geotagging support to Api::PostUpdate(), here is the modified
function:

  def PostUpdate(self, status, in_reply_to_status_id=None, lat=None,
long=None):
    '''Post a twitter status message from the authenticated user.

    The twitter.Api instance must be authenticated.

    Args:
      status:
        The message text to be posted.  Must be less than or equal to
        140 characters.
      in_reply_to_status_id:
        The ID of an existing status that the status to be posted is
        in reply to.  This implicitly sets the in_reply_to_user_id
        attribute of the resulting status to the user ID of the
        message being replied to.  Invalid/missing status IDs will be
        ignored. [Optional]
    Returns:
      A twitter.Status instance representing the message posted.
    '''
    if not self._username:
      raise TwitterError("The twitter.Api instance must be authenticated.")

    url = 'http://twitter.com/statuses/update.json'

    if len(status) > CHARACTER_LIMIT:
      raise TwitterError("Text must be less than or equal to %d characters. "
                         "Consider using PostUpdates." % CHARACTER_LIMIT)

    data = {'status': status}

    if in_reply_to_status_id:
      data['in_reply_to_status_id'] = in_reply_to_status_id

    # check for geo data
    if ( (lat != None) and (long != None) ):
        data['lat'] = lat
        data['long'] = long

    json = self._FetchUrl(url, post_data=data)
    data = simplejson.loads(json)
    self._CheckForTwitterError(data)
    return Status.NewFromJsonDict(data)

Original issue reported on code.google.com by andrewse...@gmail.com on 30 Nov 2009 at 4:26

GoogleCodeExporter commented 9 years ago
In theory, yes, python-twitter will definitely support geo.

Right now I'm holding off on any new development until a few licensing 
questions are 
addressed, but hopefully this is mostly just a formality:

  https://groups.google.com/group/twitter-development-
talk/browse_thread/thread/9f90046f6469fb7b/64add3e7a298b395

In the meantime, you may want to clone the project and make the changes you 
listed 
above:

  http://code.google.com/p/python-twitter/source/checkout

Once the licensing is dealt with we can merge the new code back in from the 
clone.

And if you do make a clone to support geo, please feel free to mention it here, 
so 
others interested can pull from it even before it hits the main development 
branch.

Thanks!

Original comment by dclinton on 2 Dec 2009 at 2:49

GoogleCodeExporter commented 9 years ago
Clone created here:
https://code.google.com/r/andrewseigner-python-twitter/source/browse/twitter.py

diff summary:
added geo, trends, and rate limit support

detailed changes:
added Status::GetLocation()
added Status::SetLocation()
added geo support to Status::NewFromJsonDict()
added Api::GetTrendsCurrent()
added Api::GetRateLimitStatus()
added Api::MaximumHitFrequency()

Original comment by andrewse...@gmail.com on 13 Dec 2009 at 1:27