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