分享

Python 获取Twitter话题 (API)

 陈永正的图书馆 2017-08-30

CODE:

[python] view plain copy
  1. #!/usr/bin/python   
  2. # -*- coding: utf-8 -*-  
  3.   
  4. ''''' 
  5. Created on 2014-06-28 
  6. @author: guaguastd 
  7. @name: top_trend_topics.py 
  8. '''  
  9.   
  10. if __name__ == '__main__':  
  11.   
  12.     # import json  
  13.     import json  
  14.       
  15.     # import login, see http://blog.csdn.net/guaguastd/article/details/31706155   
  16.     from login import twitter_login  
  17.   
  18.     # get the twitter access api  
  19.     twitter_api = twitter_login()  
  20.   
  21.     # import trend  
  22.     from trend import trend_place  
  23.   
  24.     # returns the top 10 trending topics for a specific WOEID  
  25.     while 1:  
  26.         woeid = int(raw_input("\nInput wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): "))  
  27.         if woeid == 0:  
  28.             break  
  29.       
  30.         print json.dumps(trend_place(twitter_api, woeid), indent=1)  

RESULT:

[python] view plain copy
  1. Input wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): 1  
  2. [  
  3.  {  
  4.   "created_at": "2014-07-05T21:57:13Z",   
  5.   "trends": [  
  6.    {  
  7.     "url": "http://twitter.com/search?q=%23NEDvsCRC",   
  8.     "query": "%23NEDvsCRC",   
  9.     "name": "#NEDvsCRC",   
  10.     "promoted_content": null  
  11.    },   
  12.    {  
  13.     "url": "http://twitter.com/search?q=%23GrantLandisDMMe",   
  14.     "query": "%23GrantLandisDMMe",   
  15.     "name": "#GrantLandisDMMe",   
  16.     "promoted_content": null  
  17.    },   
  18.    {  
  19.     "url": "http://twitter.com/search?q=%23HOLvsCRC",   
  20.     "query": "%23HOLvsCRC",   
  21.     "name": "#HOLvsCRC",   
  22.     "promoted_content": null  
  23.    },   
  24.    {  
  25.     "url": "http://twitter.com/search?q=%23NetherlandsvsCostaRica",   
  26.     "query": "%23NetherlandsvsCostaRica",   
  27.     "name": "#NetherlandsvsCostaRica",   
  28.     "promoted_content": null  
  29.    },   
  30.    {  
  31.     "url": "http://twitter.com/search?q=%23alargamiento",   
  32.     "query": "%23alargamiento",   
  33.     "name": "#alargamiento",   
  34.     "promoted_content": null  
  35.    },   
  36.    {  
  37.     "url": "http://twitter.com/search?q=%22Robin+Van+Torres%22",   
  38.     "query": "%22Robin+Van+Torres%22",   
  39.     "name": "Robin Van Torres",   
  40.     "promoted_content": null  
  41.    },   
  42.    {  
  43.     "url": "http://twitter.com/search?q=Kirgizi%C3%AB",   
  44.     "query": "Kirgizi%C3%AB",   
  45.     "name": "Kirgizi\u00eb",   
  46.     "promoted_content": null  
  47.    },   
  48.    {  
  49.     "url": "http://twitter.com/search?q=%22Crazy+Game%22",   
  50.     "query": "%22Crazy+Game%22",   
  51.     "name": "Crazy Game",   
  52.     "promoted_content": null  
  53.    },   
  54.    {  
  55.     "url": "http://twitter.com/search?q=%22MusulKerk%C3%BCkT%C3%BCrkistan+T%C3%BCrkElleriPeri%C5%9Fan%22",   
  56.     "query": "%22MusulKerk%C3%BCkT%C3%BCrkistan+T%C3%BCrkElleriPeri%C5%9Fan%22",   
  57.     "name": "MusulKerk\u00fckT\u00fcrkistan T\u00fcrkElleriPeri\u015fan",   
  58.     "promoted_content": null  
  59.    },   
  60.    {  
  61.     "url": "http://twitter.com/search?q=%22Fan+Persie%22",   
  62.     "query": "%22Fan+Persie%22",   
  63.     "name": "Fan Persie",   
  64.     "promoted_content": null  
  65.    }  
  66.   ],   
  67.   "as_of": "2014-07-05T22:04:56Z",   
  68.   "locations": [  
  69.    {  
  70.     "woeid": 1,   
  71.     "name": "Worldwide"  
  72.    }  
  73.   ]  
  74.  }  
  75. ]  
  76.   
  77. Input wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): 23424977  
  78. [  
  79.  {  
  80.   "created_at": "2014-07-05T22:01:08Z",   
  81.   "trends": [  
  82.    {  
  83.     "url": "http://twitter.com/search?q=%23NEDvsCRC",   
  84.     "query": "%23NEDvsCRC",   
  85.     "name": "#NEDvsCRC",   
  86.     "promoted_content": null  
  87.    },   
  88.    {  
  89.     "url": "http://twitter.com/search?q=%23GrantLandisDMMe",   
  90.     "query": "%23GrantLandisDMMe",   
  91.     "name": "#GrantLandisDMMe",   
  92.     "promoted_content": null  
  93.    },   
  94.    {  
  95.     "url": "http://twitter.com/search?q=%23CRCvsNED",   
  96.     "query": "%23CRCvsNED",   
  97.     "name": "#CRCvsNED",   
  98.     "promoted_content": null  
  99.    },   
  100.    {  
  101.     "url": "http://twitter.com/search?q=%23askskai",   
  102.     "query": "%23askskai",   
  103.     "name": "#askskai",   
  104.     "promoted_content": null  
  105.    },   
  106.    {  
  107.     "url": "http://twitter.com/search?q=%23NetherlandsvsCostaRica",   
  108.     "query": "%23NetherlandsvsCostaRica",   
  109.     "name": "#NetherlandsvsCostaRica",   
  110.     "promoted_content": null  
  111.    },   
  112.    {  
  113.     "url": "http://twitter.com/search?q=%22Happy+5th+of+July%22",   
  114.     "query": "%22Happy+5th+of+July%22",   
  115.     "name": "Happy 5th of July",   
  116.     "promoted_content": null  
  117.    },   
  118.    {  
  119.     "url": "http://twitter.com/search?q=%22Barney+Hall%22",   
  120.     "query": "%22Barney+Hall%22",   
  121.     "name": "Barney Hall",   
  122.     "promoted_content": null  
  123.    },   
  124.    {  
  125.     "url": "http://twitter.com/search?q=%22Josh+Gordon%22",   
  126.     "query": "%22Josh+Gordon%22",   
  127.     "name": "Josh Gordon",   
  128.     "promoted_content": null  
  129.    },   
  130.    {  
  131.     "url": "http://twitter.com/search?q=%22Van+Persie%22",   
  132.     "query": "%22Van+Persie%22",   
  133.     "name": "Van Persie",   
  134.     "promoted_content": null  
  135.    },   
  136.    {  
  137.     "url": "http://twitter.com/search?q=Cervelli",   
  138.     "query": "Cervelli",   
  139.     "name": "Cervelli",   
  140.     "promoted_content": null  
  141.    }  
  142.   ],   
  143.   "as_of": "2014-07-05T22:05:15Z",   
  144.   "locations": [  
  145.    {  
  146.     "woeid": 23424977,   
  147.     "name": "United States"  
  148.    }  
  149.   ]  
  150.  }  
  151. ]  
  152.   
  153. Input wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): 0  


                                    

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多