Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GoogleCodeExporter opened this issue Aug 6, 2015 · 2 comments
Open

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

GoogleCodeExporter opened this issue Aug 6, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 28 Apr 2012 at 1:39

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 15 May 2013 at 2:36

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant