Files
airflow/dags/stat/aiprice/nonghang_use.py
T
2025-02-13 13:18:15 +08:00

37 lines
1.7 KiB
Python

import requests
import ssl
import datetime
import urllib3
from goojia_utils import nextcloudutils, dingutils
# 禁用 InsecureRequestWarning
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# 获取当前日期
current_date = datetime.datetime.now()
# 计算前一日的日期
previous_date = current_date - datetime.timedelta(days=1)
# 格式化日期
formatted_date = previous_date.strftime("%Y.%m.%d")
data = {
"parentCode": "001.002",
"dateRange": formatted_date + "," + formatted_date
}
headers = {
"Accept": "*/*",
"Content-Type": "application/json",
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJhY2NvdW50IjoiYWlyZmxvdyIsImV4cCI6MTMxMzM5NDE2MzQwNDYxLCJvcmdDb2RlIjoiMDAxLjAwMSIsInJvbGVzIjpbIm5vcm1hbCJdLCJ1c2VySWQiOiIxODg5ODc0MDc4MTgxODMwNjU2IiwidXNlcm5hbWUiOiLlrprml7bku7vliqEifQ.SvD42b8XGlxYe_0dBr215ZgxR9aBdsipaySceZuuWR6g5cHelU5oc-dRtK63b0CMoN07BSvh2XYdlIzQ92ngOA"
}
ret = requests.post(url='https://api.fangjia.com/exportStatistics', json=data, headers=headers, verify=False)
#ret = requests.post(url='http://127.0.0.1:8080/exportStatistics', json=data, headers=headers, verify=False)
nextcloud_aim_file_path = '共享/AI估价/农行统计'
file_path = "AI估价农行" + formatted_date + ".xlsx"
with open(file_path, 'wb') as file:
# 将字节流写入文件
file.write(ret.content)
nextcloudutils.up_to_nextcloud(file_path, nextcloud_aim_file_path + "/" + "AI估价农行" + formatted_date + ".xlsx")
dingutils.send_text("【AI估价】农行" + formatted_date + "统计完成, 请点击 https://nextcloud.fangjia.com/s/WK9MzWwH5kjwMBB 查看", "f4f3b03c35c67d097f70affa27e7d47d7a1b6c0eed2438f4d8aa654834419a0b")