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)

Python 获取新浪微博的热门话题 (API),布布扣,bubuko.com

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

上一篇:关于时间的操作(JavaScript版)——页面显示格式:年月日 上午下午 时分秒 星期


下一篇:初探C++运算符重载学习笔记<1>