Python 获取新浪微博的热门话题 (API)


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

'''
Created on 2014-06-27
@author: guaguastd

'''

import json


# Refer to http://blog.csdn.net/guaguastd/article/details/33664443

from login import weibo_login


# sina weibo basic secret information
APP_KEY = '' # app key
APP_SECRET = '' # app secret
REDIRECT_URL = ''
USER_NAME = ''
USER_PASSWD = ''
    
# get weibo_api to access sina api
weibo_api = weibo_login(APP_KEY=APP_KEY, APP_SECRET=APP_SECRET, REDIRECT_URL=REDIRECT_URL, USER_NAME=USER_NAME, USER_PASSWD=USER_PASSWD)

# get trends by hourly, by daily, by weekly
while 1:
    choice = int(raw_input("\ninput choice to get trends (1 means hourly, 2 means daily, 3 means weekly, 0 to quit):"))
    if choice == 0:
        break
    elif choice == 1:
        print 'Hourly trends are as follow:\r'
        hourly_trends = weibo_api.trends.hourly.get()
        print json.dumps(hourly_trends, indent=1)
    elif choice == 2:
        print 'Daily trends are as follow:\r'
        daily_trends = weibo_api.trends.daily.get()
        print json.dumps(daily_trends, indent=1)
    elif choice == 3:
        print 'Weekly trends are as follow:\r'
        weekly_trends = weibo_api.trends.weekly.get()
        print json.dumps(weekly_trends, indent=1)

相关内容

    暂无相关文章