开发原因
e能家园查询电费,每次都要进入微信公众号查询太麻烦
代码
import requests,json,time
class Df_api():
def __init__(self):
super().__init__()
login_data = {"hh":"账号","password":"密码"}
self.header = {"Accept": "application/json, text/plain, */*",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9",
"Content-Length": "17",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "hl.energyman.cn",
"Origin": "http://hl.energyman.cn",
"Proxy-Connection": "keep-alive",
"Referer": "http://hl.energyman.cn/wxemcp/wx/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x6309021a) XWEB/6939 Flue"}
self.url = "http://hl.energyman.cn/wxemcp/"
back_text = requests.post(self.url+"mine/loginHH",data=login_data,headers=self.header).text
self.customerid = json.loads(back_text)["data"]["customerid"]
def get_current_month(self):
current_month_data = {"customerid":self.customerid,"date":time.strftime("%Y-%m", time.localtime()),"type":"1"}
back_text = requests.post(self.url+"elec/billDetail",data=current_month_data,headers=self.header).text
back_data = json.loads(back_text)["data"]["top"]
back_detailed_data = json.loads(back_text)["data"]["list"][0]
# back_detailed_data = json.loads(back_detailed_data_list)
export_back_text = {"开始时间":back_data["datatime"],"截止时间":back_detailed_data["time"],"户名":back_data["hm"],"总余额":back_data["change"],"应扣余额":back_data["should"],"可用余额":back_data["balance"],"用电量(度)":back_detailed_data["data"]["energy"],"单价(元/度)":back_detailed_data["pricerule"]["value1"]}
return export_back_text
a = Df_api().get_current_month()
print(a)
程序运行结果
{'开始时间': '2023-06-01 00:00:00', '截止时间': '2023-06-10 14:00:00', '户名': '00000', '总余额': 102.11, '应扣余额': 63.35, '可用余额': 38.76, '用电量(度)': 113.13, '单价(元/度)': 0.56}
返回的是json,方便接入其他程序