I'd like to convert the result of a Tweepy api.trends_location(woeid)
call to a dict (or a dict of dicts), so I can work with the values (really, I want to end up with a dict of the 'name' values). The Tweepy documentation says that the result is 'a JSON object' (see here), but when I retrieve it, type(retrieved)
evaluates to list
. Sure enough, retrieved
has a len
of 1, and retrieved[0]
gives me a single item:
[{'trends': [{'url': 'http://search.twitter.com/search?q=%23questionsidontlike', 'query': '%23questionsidontlike', 'events': None, 'promoted_content': None, 'name': '#questionsidontlike'}, ], (more of the same), 'created_at': '2011-01-31T22:39:16Z', 'as_of': '2011-01-31T22:47:47Z', 'locations': [{'woeid': 23424977, 'name': 'United States'}]}]
.
I can call json.dumps
, which will give a nicely-formatted representation, but that's not much use to me, and json.loads
gives me: __init__() got an unexpected keyword argument 'sort_keys'
How should I proceed?
Link to full code: https://gist.github.com/805129