[python]代码库
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json, urllib
from urllib import urlencode
#----------------------------------
# 星座运势调用示例代码 - 聚合数据
# 在线接口文档:http://www.juhe.cn/docs/58
#----------------------------------
def main():
#配置您申请的APPKey
appkey = "*********************"
#1.运势查询
request1(appkey,"GET")
#运势查询
def request1(appkey, m="GET"):
url = "http://web.juhe.cn:8080/constellation/getAll"
params = {
"key" : appkey, #应用APPKEY(应用详细页查询)
"consName" : "", #星座名称,如:白羊座
"type" : "", #运势类型:today,tomorrow,week,nextweek,month,year
}
params = urlencode(params)
if m =="GET":
f = urllib.urlopen("%s?%s" % (url, params))
else:
f = urllib.urlopen(url, params)
content = f.read()
res = json.loads(content)
if res:
error_code = res["error_code"]
if error_code == 0:
#成功请求
print res["result"]
else:
print "%s:%s" % (res["error_code"],res["reason"])
else:
print "request api error"
if __name__ == '__main__':
main()