python微博热点_Python 获取新浪微博的热门话题 (API)

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 = sinaWeiboLogin()

# get sinaWeiboTrend

from sinaWeiboTrend import trendClass

trends = trendClass(sinaWeiboApi)

# get sinaWeiboTrend by hourly, by daily, by weekly

while 1:

while True:

choice = raw_input("\ninput choice to get sinaWeiboTrend (1 means hourly, 2 means daily, 3 means weekly, 0 to quit):")

if choice.isdigit():

choice = int(choice)

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_trend()

print json.dumps(hourly_trends, indent=1)

elif choice == 2:

print 'Daily sinaWeiboTrend are as follow:\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()

print json.dumps(weekly_trends, indent=1)

else:

print 'Input error, try again!\r'

RESULT:

input choice to get sinaWeiboTrend (1 means hourly, 2

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值