Tweepy 呼び出しの結果を dict (または dict の dict) に変換したいapi.trends_location(woeid)
ので、値を操作できます (実際には、'name' 値の dict で終わりたいです)。Tweepy のドキュメントには、結果が「JSON オブジェクト」であると記載されていますが (こちらを参照)、取得すると、. 案の定、 は1 で、単一のアイテムが得られます: . type(retrieved)
list
retrieved
len
retrieved[0]
[{'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'}]}]
を呼び出すとjson.dumps
、きれいにフォーマットされた表現が得られますが、それはあまり役に立たず、次のようになりjson.loads
ます。__init__() got an unexpected keyword argument 'sort_keys'
どのように進めればよいですか?
完全なコードへのリンク: https://gist.github.com/805129