首页 八字排盘 八字排盘示例代码 八字排盘urllib版[Python]

八字排盘urllib版示例代码Python

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

八字排盘urllib版

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

import urllib2, json, urllib

#  1、八字排盘

data = {}
data["appkey"] = "your_appkey_here"
data["city"] = ""
data["year"] = 2009
data["month"] = 10
data["day"] = 18
data["hour"] = 2
data["minute"] =5
data["sex"] = 1
data["istaiyang"] = 0
data["islunar"] = 0
url_values = urllib.urlencode(data)
url = "https://api.jisuapi.com/bazi/paipan" + "?" + url_values
request = urllib2.Request(url)
result = urllib2.urlopen(request)
jsonarr = json.loads(result.read())
if jsonarr["status"] != 0:
    print(jsonarr["msg"])
    exit()
result = jsonarr["result"]
print(result["year"],result["month"],result["day"],result["hour"],result["minute"],result["name"],result["city"],result["istaiyang"],result["lunaryear"],result["lunarmonth"],result["lunarday"],result["lunarhour"],result["animal"],result["yearganzhi"]
print("上一个节气:"
print(result["jieqiprev"]["jieqiname"],result["jieqiprev"]["date"],
print("下一个节气:"
print(result["jieqinext"]["jieqiname"],result["jieqinext"]["date"]
str = ""
for v in result["qiankunzao"][2]:
    str += " ".join(v)
print(" ".join(result["bazi"]),result["taiyuan"],result["minggong"]," ".join(result["xunkong"])
print(" ".join(result["qiyun"])," ".join(result["jiaoyun"])
print(" ".join(result["qiankunzao"][0])," ".join(result["qiankunzao"][1]),str
print(" ".join(result["nayin"])
for shensha in result["shensha"]:
    print(" ".join(shensha)
    
dayun = result["dayun"]
print(" ".join(dayun["nayin"])
print(" ".join(dayun["shishen"])
print(" ".join(dayun["ganzhi"])
print(" ".join(dayun["sui"])
print("流年:"
for liunian in result["liunian"]:
    print(" ".join(liunian))