AshleyFernandez / python-twitter

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

twitter.Api.GetTrendsCurrent() does not work #231

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. attempt to execute twitter.Api.GetTrendsCurrent()
2.
3.

What is the expected output? What do you see instead?

The list of triends should be assigned

This is what I get instead

>>> a = api.GetTrendsCurrent()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "twitter.py", line 2435, in GetTrendsCurrent
    for t in data['trends']:
KeyError: 'trends'

What version of the product are you using? On what operating system?

python-twitter 0.8.2 with python 2.7.2 on ubuntu linux 

Please provide any additional information below.

The GET trends/current call is listed as deprecated on dev.twitter.com

The new call is GET trends/:woeid to get the top 10 trends for "woeid" and GET 
trends/available to list woeid available

Original issue reported on code.google.com by Kris.Mus...@gmail.com on 28 Apr 2012 at 1:39

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I have the same problem on Freebsd 9.0/amd64

Temporary workarround is to define the method yourself

def GetTrendsCurrent(self, exclude=None, woeid="1"):
        parameters = {}
        if exclude:
                parameters['exclude'] = exclude
        url = '%(url)s/trends/%(woeid)s.json' % { "url" : self.base_url, "woeid" : woeid }
        json = self._FetchUrl(url, parameters=parameters)
        data = simplejson.loads(json)
        self._CheckForTwitterError(data)
        trends = []

        for t in data[0]['trends']:
                trends.append(twitter.Trend.NewFromJsonDict(t, timestamp = data[0]['created_at']))
        return trends

Then override the api's method with your new method

api.GetTrendsCurrent = types.MethodType( GetTrendsCurrent, api )

I have attached a patch

Original comment by Daniel.F...@gmail.com on 15 May 2013 at 2:36

Attachments: