首页 星座运势 星座运势示例代码 星座运势查询[Python]

星座运势查询示例代码[Python]

作者:liuxiaojie 阅读数:2725 上传时间:2016-03-10

星座运势查询

#!/usr/bin/python
# encoding:utf-8

import urllib2, json, urllib


#  2、星座运势查询

data = {}
data["appkey"] = "your_appkey_here"
data["astroid"] = 1
data["date"] = "2016-01-19"

url_values = urllib.urlencode(data)
url = "https://api.jisuapi.com/astro/fortune" + "?" + url_values
request = urllib2.Request(url)
result = urllib2.urlopen(request)
jsonarr = json.loads(result.read())

if jsonarr["status"] != u"0":
    print jsonarr["msg"]
    exit()
result = jsonarr["result"]
print result
print result["astroid"],result["astroname"]
today = result["today"]
tomorrow = result["tomorrow"]
month = result["month"]

print "今日运势:"
print today["date"],today["presummary"],today["star"],today["color"],today["number"],today["summary"],today["money"],today["career"],today["love"],today["health"]
print "明日运势:"
print tomorrow["date"],tomorrow["presummary"],tomorrow["star"],tomorrow["color"],tomorrow["number"],tomorrow["summary"],tomorrow["money"],tomorrow["career"],tomorrow["love"],tomorrow["health"]
if result.has_key("week"):
    week = result["week"]
    print "本周运势:"
    print week["date"],week["job"],week["money"],week["career"],week["love"],week["health"]
print "本月运势:"
print month["date"],month["summary"],month["money"],month["career"],month["love"],month["health"]
if result.has_key("year"):
    year = result["year"]
    print "本年运势:"
    print year["date"],year["summary"],year["money"],year["career"],year["love"]