Issue 231 in python-twitter: twitter.Api.GetTrendsCurrent() does not work

70 views
Skip to first unread message

python-...@googlecode.com

unread,
Apr 28, 2012, 9:39:53 AM4/28/12
to python-twi...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 231 by Kris.Mus...@gmail.com: twitter.Api.GetTrendsCurrent() does
not work
http://code.google.com/p/python-twitter/issues/detail?id=231

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

python-...@googlecode.com

unread,
May 14, 2013, 10:22:15 PM5/14/13
to python-twi...@googlegroups.com

Comment #1 on issue 231 by Daniel.F...@gmail.com:
twitter.Api.GetTrendsCurrent() does not work
http://code.google.com/p/python-twitter/issues/detail?id=231

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

Attachments:
patch-GetTrendsCurrent.diff 1.1 KB

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

python-...@googlecode.com

unread,
May 14, 2013, 10:36:50 PM5/14/13
to python-twi...@googlegroups.com

Comment #2 on issue 231 by Daniel.F...@gmail.com:
twitter.Api.GetTrendsCurrent() does not work
http://code.google.com/p/python-twitter/issues/detail?id=231

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

Attachments:
patch-GetTrendsCurrent.diff 1.5 KB
Reply all
Reply to author
Forward
0 new messages