Python 获取Twitter话题 (API)

CODE:

#!/usr/bin/python 
# -*- coding: utf-8 -*-

'''
Created on 2014-06-28
@author: guaguastd
@name: top_trend_topics.py
'''

if __name__ == '__main__':

    # import json
    import json
    
    # import login, see http://blog.csdn.net/guaguastd/article/details/31706155 
    from login import twitter_login

    # get the twitter access api
    twitter_api = twitter_login()

    # import trend
    from trend import trend_place

    # returns the top 10 trending topics for a specific WOEID
    while 1:
        woeid = int(raw_input("\nInput wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): "))
        if woeid == 0:
            break
    
        print json.dumps(trend_place(twitter_api, woeid), indent=1)

RESULT:

Input wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): 1
[
 {
  "created_at": "2014-07-05T21:57:13Z", 
  "trends": [
   {
    "url": "http://twitter.com/search?q=%23NEDvsCRC", 
    "query": "%23NEDvsCRC", 
    "name": "#NEDvsCRC", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23GrantLandisDMMe", 
    "query": "%23GrantLandisDMMe", 
    "name": "#GrantLandisDMMe", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23HOLvsCRC", 
    "query": "%23HOLvsCRC", 
    "name": "#HOLvsCRC", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23NetherlandsvsCostaRica", 
    "query": "%23NetherlandsvsCostaRica", 
    "name": "#NetherlandsvsCostaRica", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23alargamiento", 
    "query": "%23alargamiento", 
    "name": "#alargamiento", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Robin+Van+Torres%22", 
    "query": "%22Robin+Van+Torres%22", 
    "name": "Robin Van Torres", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=Kirgizi%C3%AB", 
    "query": "Kirgizi%C3%AB", 
    "name": "Kirgizi\u00eb", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Crazy+Game%22", 
    "query": "%22Crazy+Game%22", 
    "name": "Crazy Game", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22MusulKerk%C3%BCkT%C3%BCrkistan+T%C3%BCrkElleriPeri%C5%9Fan%22", 
    "query": "%22MusulKerk%C3%BCkT%C3%BCrkistan+T%C3%BCrkElleriPeri%C5%9Fan%22", 
    "name": "MusulKerk\u00fckT\u00fcrkistan T\u00fcrkElleriPeri\u015fan", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Fan+Persie%22", 
    "query": "%22Fan+Persie%22", 
    "name": "Fan Persie", 
    "promoted_content": null
   }
  ], 
  "as_of": "2014-07-05T22:04:56Z", 
  "locations": [
   {
    "woeid": 1, 
    "name": "Worldwide"
   }
  ]
 }
]

Input wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): 23424977
[
 {
  "created_at": "2014-07-05T22:01:08Z", 
  "trends": [
   {
    "url": "http://twitter.com/search?q=%23NEDvsCRC", 
    "query": "%23NEDvsCRC", 
    "name": "#NEDvsCRC", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23GrantLandisDMMe", 
    "query": "%23GrantLandisDMMe", 
    "name": "#GrantLandisDMMe", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23CRCvsNED", 
    "query": "%23CRCvsNED", 
    "name": "#CRCvsNED", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23askskai", 
    "query": "%23askskai", 
    "name": "#askskai", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23NetherlandsvsCostaRica", 
    "query": "%23NetherlandsvsCostaRica", 
    "name": "#NetherlandsvsCostaRica", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Happy+5th+of+July%22", 
    "query": "%22Happy+5th+of+July%22", 
    "name": "Happy 5th of July", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Barney+Hall%22", 
    "query": "%22Barney+Hall%22", 
    "name": "Barney Hall", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Josh+Gordon%22", 
    "query": "%22Josh+Gordon%22", 
    "name": "Josh Gordon", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Van+Persie%22", 
    "query": "%22Van+Persie%22", 
    "name": "Van Persie", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=Cervelli", 
    "query": "Cervelli", 
    "name": "Cervelli", 
    "promoted_content": null
   }
  ], 
  "as_of": "2014-07-05T22:05:15Z", 
  "locations": [
   {
    "woeid": 23424977, 
    "name": "United States"
   }
  ]
 }
]

Input wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): 0


                
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值