4.18备份
This commit is contained in:
+106
-13
@@ -3,6 +3,10 @@ import requests
|
||||
from module import F6_module
|
||||
import time
|
||||
from tqdm import tqdm
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
import json
|
||||
import traceback
|
||||
|
||||
#+
|
||||
# f6_module = F6_module()
|
||||
@@ -17,22 +21,27 @@ module = 2
|
||||
# # cookies = requests.utils.dict_from_cookiejar(res.cookies)
|
||||
|
||||
cookies = {
|
||||
'memberSESSIONID': 'a6c5084a-7393-426e-9cdc-c3fb8c0d6960',
|
||||
'memberSESSIONID': '38d027b4-1f86-44fe-a8d2-2211fbd46394',
|
||||
'erpLanguage': 'zh-CN',
|
||||
'tmall': 'false',
|
||||
'Hm_lvt_25f5e7a3a5dbb293d7dd35d5f1be8d0a': '1760494904,1760510876,1760584685,1760671187',
|
||||
'HMACCOUNT': '55F2182717FD6AE6',
|
||||
'prodOrg': '16001002822673915925',
|
||||
'unp': '16001002823772827677',
|
||||
'un': '16001002823772827677',
|
||||
'_up': '-NillNN-qyBEJ--t3vnSknvoOF1_zfCNsM8N0Xg4XeVVVPbHoJ7QjaZJ9Q3d-WrAAGgt60MgQHajHWBHMKKxj0CuWypi1JgKCFP1EPEk-HbqEvMdqoIq3wEI9_JRv-ZNHu3M-GTf3piwFXeqpu9WjuwYmFTEOBRorEj9mmew_aOwUBk.',
|
||||
'sensorsdata2015jssdkcross': '%7B%22distinct_id%22%3A%2216001002823772827677%22%2C%22first_id%22%3A%22198a89fdaa54f-0a897244f8104b8-4c657b58-2073600-198a89fdaa61b71%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%22198a89fdaa54f-0a897244f8104b8-4c657b58-2073600-198a89fdaa61b71%22%7D',
|
||||
'Hm_lpvt_25f5e7a3a5dbb293d7dd35d5f1be8d0a': '1760939885',
|
||||
'Hm_lvt_25f5e7a3a5dbb293d7dd35d5f1be8d0a': '1775553704,1775799422,1776043595,1776153876',
|
||||
'HMACCOUNT': 'A6A0585E8C70051D',
|
||||
'prodOrg': '11240984669918128522',
|
||||
'unp': '15851362811188895763',
|
||||
'un': '15851362811188895763',
|
||||
'_up': '-NillNN-qyBEJ--t3vnSknvoOF53yPCOts8N0no-Uu9VX_TGoZrQjaZJ9Q3d-WrAAGgt60MgQHajHWBHMKKxj0CuWypi1JgKCFP1EPEk-HbqE_UXoIgm0QIF_PBRv-ZNHu3M-GTc1p2wFnGqpuxUiOMSmF_GORVsrEj92RzBn7rDYmA.',
|
||||
'sensorsdata2015jssdkcross': '%7B%22distinct_id%22%3A%2215851362811188895763%22%2C%22first_id%22%3A%2219b6df76a22f46-04a98afdd2a11d8-4c657b58-1327104-19b6df76a2312c7%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%2219b6df76a22f46-04a98afdd2a11d8-4c657b58-1327104-19b6df76a2312c7%22%7D',
|
||||
'Hm_lpvt_25f5e7a3a5dbb293d7dd35d5f1be8d0a': '1776393475',
|
||||
}
|
||||
|
||||
print(cookies) # 登录获取cookies
|
||||
print("cookies loaded")
|
||||
|
||||
df = pd.read_excel(fr"C:\Users\zy187\Desktop\钉钉文件\车辆信息-修复-太乙1020.xls",sheet_name="Sheet4").astype(str)
|
||||
request_results = []
|
||||
script_dir = Path(__file__).resolve().parent
|
||||
output_base = script_dir / f"请求结果_{datetime.now():%Y%m%d_%H%M%S}"
|
||||
|
||||
|
||||
df = pd.read_excel(fr"D:\Idea Project\F6+宜搭+其它(1)\张阳脚本\文件输出\车辆信息.xlsx",sheet_name="Sheet2").astype(str)
|
||||
|
||||
|
||||
if module == 1: # 客户信息删除
|
||||
@@ -40,6 +49,17 @@ if module == 1: # 客户信息删除
|
||||
df['手机号码'].dropna(inplace=True)
|
||||
url = "https://yunxiu.f6car.cn/member/customer/listForPermission?pageSize=50000&pageNo=1" # 获取客户信息列表
|
||||
res = requests.get(url, cookies=cookies)
|
||||
row = {"ts": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "module": module, "action": "customer_list", "url": url}
|
||||
row["status_code"] = getattr(res, "status_code", None)
|
||||
row["ok"] = getattr(res, "ok", None)
|
||||
try:
|
||||
row["response_json"] = json.dumps(res.json(), ensure_ascii=False)
|
||||
except Exception:
|
||||
try:
|
||||
row["response_text"] = res.text
|
||||
except Exception:
|
||||
row["response_text"] = None
|
||||
request_results.append(row)
|
||||
data = res.json()
|
||||
for item in tqdm(data['data']['data']):
|
||||
try:
|
||||
@@ -50,6 +70,24 @@ if module == 1: # 客户信息删除
|
||||
print("删除:", phone)
|
||||
url = f"https://yunxiu.f6car.cn/member/customer/{idCustomer}" # 客户信息删除url
|
||||
res = requests.delete(url, cookies=cookies) # 客户信息删除
|
||||
row = {
|
||||
"ts": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"module": module,
|
||||
"action": "customer_delete",
|
||||
"url": url,
|
||||
"idCustomer": idCustomer,
|
||||
"cellPhone": phone_clean,
|
||||
}
|
||||
row["status_code"] = getattr(res, "status_code", None)
|
||||
row["ok"] = getattr(res, "ok", None)
|
||||
try:
|
||||
row["response_json"] = json.dumps(res.json(), ensure_ascii=False)
|
||||
except Exception:
|
||||
try:
|
||||
row["response_text"] = res.text
|
||||
except Exception:
|
||||
row["response_text"] = None
|
||||
request_results.append(row)
|
||||
print(res.json(), idCustomer, phone)
|
||||
time.sleep(3)
|
||||
else:
|
||||
@@ -69,14 +107,69 @@ if module == 2: # 客户车辆信息删除
|
||||
url = f"https://yunxiu.f6car.cn/member/car/deleteCar/{car_Id}/{customerId}"
|
||||
# url = f"https://yunxiu.f6car.cn/macan/coupon/car/batchRemove?customerId={customerId}&carId={carId}&operateOrgId={operateOrgId}" # 删除客户车辆信息url
|
||||
res = requests.delete(url, cookies=cookies) # 客户车辆信息删除
|
||||
row = {
|
||||
"ts": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"module": module,
|
||||
"action": "car_delete",
|
||||
"url": url,
|
||||
"car_number": car_number,
|
||||
"carId": car_Id,
|
||||
"customerId": customerId,
|
||||
}
|
||||
row["status_code"] = getattr(res, "status_code", None)
|
||||
row["ok"] = getattr(res, "ok", None)
|
||||
try:
|
||||
row["response_json"] = json.dumps(res.json(), ensure_ascii=False)
|
||||
except Exception:
|
||||
try:
|
||||
row["response_text"] = res.text
|
||||
except Exception:
|
||||
row["response_text"] = None
|
||||
request_results.append(row)
|
||||
print("delete——", res.json(), customerId, car_Id)
|
||||
|
||||
from datetime import datetime
|
||||
now = datetime.now()
|
||||
if now.hour >= 20:
|
||||
time.sleep(1)
|
||||
else:
|
||||
time.sleep(3)
|
||||
except:
|
||||
print("删除失败:", res.json(), customerId, car_Id)
|
||||
res_tmp = locals().get("res")
|
||||
row = {
|
||||
"ts": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"module": module,
|
||||
"action": "car_delete",
|
||||
"url": locals().get("url"),
|
||||
"car_number": car_number,
|
||||
"carId": car_Id,
|
||||
"customerId": customerId,
|
||||
"error": "删除失败",
|
||||
"traceback": traceback.format_exc(),
|
||||
}
|
||||
if res_tmp is not None:
|
||||
row["status_code"] = getattr(res_tmp, "status_code", None)
|
||||
row["ok"] = getattr(res_tmp, "ok", None)
|
||||
try:
|
||||
row["response_json"] = json.dumps(res_tmp.json(), ensure_ascii=False)
|
||||
except Exception:
|
||||
try:
|
||||
row["response_text"] = res_tmp.text
|
||||
except Exception:
|
||||
row["response_text"] = None
|
||||
request_results.append(row)
|
||||
try:
|
||||
print("删除失败:", res_tmp.json(), customerId, car_Id)
|
||||
except Exception:
|
||||
print("删除失败:", getattr(res_tmp, "text", None), customerId, car_Id)
|
||||
continue
|
||||
|
||||
if request_results:
|
||||
df_out = pd.DataFrame(request_results)
|
||||
df_out.to_csv(f"{output_base}.csv", index=False, encoding="utf-8-sig")
|
||||
with open(f"{output_base}.jsonl", "w", encoding="utf-8") as f:
|
||||
for row in request_results:
|
||||
f.write(json.dumps(row, ensure_ascii=False) + "\n")
|
||||
try:
|
||||
df_out.to_excel(f"{output_base}.xlsx", index=False)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user