How Python Gets the hot topic of Sina Weibo (API)

Source: Internet
Author: User
Tags json

Code:

#!/usr/bin/python #-*-Coding:utf-8-*-' Created on 2014-06-27 @author: guaguastd @name: sinaweibohottrend.py ' Import JSON from sinaweibologin import Sinaweibologin # get Weibo_api to access Sina API Sinaweiboapi = Sinaweibol Ogin () # get Sinaweibotrend to sinaweibotrend import trendclass trends = Trendclass (SINAWEIBOAPI) # get Sinaweibotre nd by hourly, by daily, by weekly while 1:while True:choice = Raw_input ("\ninput Choice-Get Sinaweibotren D (1 means hourly, 2 means daily, 3 means weekly, 0 to quit): ") if Choice.isdigit (): choice = Int (choi
                CE) if choice = = 0 or Choice = = 1 or choice = 2 or choice = = 3:break Else:
            
        print ' input error, should input int number among 0,1,2,3, try Again! '
            
    Else:print ' input error, should input int number, please try Again! ' if choice = = 0:print ' succssfully exit!\r ' break
    elif Choice = = 1:print ' hourly sinaweibotrend are as follow:\r ' hourly_trends = trends.hourly_new_tr End () print json.dumps (Hourly_trends, indent=1) elif choice = = 2:print ' daily sinaweibotrend are as F  ollow:\r ' daily_trends = Trends.daily_new_trend () print json.dumps (Daily_trends, indent=1) elif choice = = 3:print ' Weekly sinaweibotrend are as follow:\r ' weekly_trends = trends.weekly_new_trend () pr int Json.dumps (weekly_trends, indent=1) else:print ' Input error, try Again!\r '


Result:

Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/

Input choice to get Sinaweibotrend (1 means hourly, 2 means daily, 3 means weekly, 0 to quit): 1 hourly sinaweibotrend are As follow: {"Trends": {"2014-07-06 08:16": [{"Query": "\u6797\u5999\u53ef", "Amount": "26088", "N 
    Ame ":" \u6797\u5999\u53ef "," Delta ":" 26088 "}, {" Query ":" \u8d1d\u513ffeynman "," Amount ":" 24442 ", "Name": "\u8d1d\u513ffeynman", "Delta": "24442"}, {"Query": "\u5434\u901f\u73b2", "Amount": "2 2423 "," name ":" \u5434\u901f\u73b2 "," Delta ":" 22423 "}, {" Query ":" \u8a00\u627f\u65ed "," Amoun T ":" 21956 "," name ":" \u8a00\u627f\u65ed "," Delta ":" 21956 "}, {" Query ":" \u5434\u5988 "," Amoun T ":" 21533 "," name ":" \u5434\u5988 "," Delta ":" 21533 "}, {" Query ":" \u591a\u59887788 "," Amount " : "21314", "name": "\u591a\u59887788", "Delta": "21314"}, {"Query": "\u52a0\u6cb9\u5434\u4ea6\u51e1 "," Amount ":" 21051"," name ":" \u52a0\u6cb9\u5434\u4ea6\u51e1 "," Delta ":" 21051 "}, {" Query ":" \U5305\U5B50\U59B9 ", "Amount": "20939", "name": "\u5305\u5b50\u59b9", "Delta": "20939"}, {"Query": "\u7537\u795e\u9e7f 
    \u6657\u91cd\u8fd4\u5feb\u672c "," Amount ":" 20570 "," name ":" \u7537\u795e\u9e7f\u6657\u91cd\u8fd4\u5feb\u672c ", 
    "Delta": "20570"}, {"Query": "\u8377\u5170 \u54e5\u65af\u8fbe\u9ece\u52a0", "Amount": "20033",  ' Name ': ' \u8377\u5170 \u54e5\u65af\u8fbe\u9ece\u52a0 ', ' Delta ': ' 20033 '}]}, ' as_of ': 1404605804} input Choice to get Sinaweibotrend (1 means hourly, 2 means daily, 3 means weekly, 0 to quit): 2 daily sinaweibotrend are as fol Low: {"Trends": {"2014-07-06 08:23": [{"Query": "\u6797\u5999\u53ef", "Amount": "26434", "Name": " \u6797\u5999\u53ef ", Delta": "26434"}, {"Query": "\u8d1d\u513ffeynman", "Amount": "24677", "N Ame ":" \u8d1d\u513ffeynmAn ", Delta": "24677"}, {"Query": "\u5434\u901f\u73b2", "Amount": "22716", "name": "\u5434\u90 1f\u73b2 ", Delta": "22716"}, {"Query": "\u8a00\u627f\u65ed", "Amount": "22315", "name": "\u8a 00\u627f\u65ed ", Delta": "22315"}, {"Query": "\u8377\u5170 \u54e5\u65af\u8fbe\u9ece\u52a0", "Amoun T ":" 22162 "," name ":" \u8377\u5170 \u54e5\u65af\u8fbe\u9ece\u52a0 "," Delta ":" 22162 "}, {" query ":" \ u5434\u5988 "," Amount ":" 21776 "," name ":" \u5434\u5988 "," Delta ":" 21776 "}, {" Query ":" \u52a0\
   U6cb9\u5434\u4ea6\u51e1 "," Amount ":" 21389 "," name ":" \u52a0\u6cb9\u5434\u4ea6\u51e1 "," Delta ":" 21389 " }, {"Query": "\U5305\U5B50\U59B9", "Amount": "21232", "name": "\u5305\u5b50\u59b9", "Delta": "2123 
    2 "}, {" Query ":" \u53e4\u4e3d\u7c73\u5a1c "," Amount ":" 19406 "," name ":" \u53e4\u4e3d\u7c73\u5a1c ",
   "Delta": "19406"}, {"Query": "\u91d1\u661f", "Amount": "19130", "name": "\u91d1\u661f", "Delta": "19130"}] }, "As_of": 1404606238} input choice to get Sinaweibotrend (1 means hourly, 2 means daily, 3 means weekly, 0 to quit 
    ): 3 Weekly sinaweibotrend are as follow: {"Trends": {"2014-07-06 08:24": [{"Query": "\u6797\u5999\u53ef", "Amount": "26434", "name": "\u6797\u5999\u53ef", "Delta": "26434"}, {"Query": "\u8d1d\u513ffeynm An "," Amount ":" 24677 "," name ":" \u8d1d\u513ffeynman "," Delta ":" 24677 "}, {" Query ":" \u5434\u9 01f\u73b2 "," Amount ":" 22716 "," name ":" \u5434\u901f\u73b2 "," Delta ":" 22716 "}, {" Query ":" \u8 A00\u627f\u65ed "," Amount ":" 22315 "," name ":" \u8a00\u627f\u65ed "," Delta ":" 22315 "}, {" Query " : "\u8377\u5170 \u54e5\u65af\u8fbe\u9ece\u52a0", "Amount": "22162", "name": "\u8377\u5170 \u54e5\u65af\u8fbe\u9e Ce\u52a0 ", Delta": "22162"}, {"Query": "\u5434\u5988", "Amount": "21776", "name": "\u5434\u5988", "Delta": "2177 6 "}, {" Query ":" \U52A0\U6CB9\U5434\U4EA6\U51E1 "," Amount ":" 21389 "," name ":" \u52a0\u6cb9\u5434\u4e A6\u51e1 ", Delta": "21389"}, {"Query": "\U5305\U5B50\U59B9", "Amount": "21232", "name": "\u53 05\u5b50\u59b9 ", Delta": "21232"}, {"Query": "\u53e4\u4e3d\u7c73\u5a1c", "Amount": "19406", " 
    Name ":" \u53e4\u4e3d\u7c73\u5a1c "," Delta ":" 19406 "}, {" Query ":" \u91d1\u661f "," Amount ":" 19130 ", ' Name ': ' \u91d1\u661f ', ' Delta ': ' 19130 '} ', ' as_of ': 1404606244} input choice to get Sinaweibotre ND (1 means hourly, 2 means daily, 3 means weekly, 0 to quit):
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.