NGV换源
This commit is contained in:
+20
-9
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
from datetime import datetime, timezone, timedelta
|
||||
import pandas as pd
|
||||
from holidays.countries import saint_martin as record
|
||||
from tqdm import tqdm
|
||||
import json
|
||||
from yd_api import YDAPI
|
||||
@@ -48,11 +49,11 @@ class GetYDData:
|
||||
self.systemToken = "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2"
|
||||
|
||||
# 第一段:2025-01-01 到 2025-11-01
|
||||
first_segment = ("2025-01-01T00:00:00Z", "2025-11-01T00:00:00Z")
|
||||
first_segment = ("2025-01-01T00:00:00Z", "2025-02-01T00:00:00Z")
|
||||
|
||||
# 第二段:2025-11-01 到当前时间(按月拆分)
|
||||
now_utc_str = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
monthly_segments = generate_monthly_ranges("2025-11-01T00:00:00Z", now_utc_str)
|
||||
monthly_segments = generate_monthly_ranges("2025-02-01T00:00:00Z", now_utc_str)
|
||||
|
||||
# 合并所有时间段
|
||||
self.time_ranges = [first_segment] + monthly_segments
|
||||
@@ -114,7 +115,7 @@ class GetYDData:
|
||||
n=100,
|
||||
appType=self.appType,
|
||||
systemToken=self.systemToken,
|
||||
instanceStatus="RUNNING",
|
||||
instanceStatus="",
|
||||
modifiedFromTimeGMT=start_time,
|
||||
modifiedToTimeGMT=end_time,
|
||||
)
|
||||
@@ -138,7 +139,7 @@ class GetYDData:
|
||||
n=100,
|
||||
appType=self.appType,
|
||||
systemToken=self.systemToken,
|
||||
instanceStatus="RUNNING",
|
||||
instanceStatus="",
|
||||
modifiedFromTimeGMT=start_time,
|
||||
modifiedToTimeGMT=end_time,
|
||||
)
|
||||
@@ -162,14 +163,20 @@ class GetYDData:
|
||||
|
||||
# Step 2: 按时间段拉取
|
||||
all_records = []
|
||||
all_records_detils = []
|
||||
for start_time, end_time in self.time_ranges:
|
||||
print(f"\n⏳ 拉取: {start_time} → {end_time}")
|
||||
records = self.fetch_records_in_range(token, start_time, end_time)
|
||||
all_records.extend(records)
|
||||
try:
|
||||
record_data = record.get("data", [])
|
||||
all_records_detils.extend(record_data)
|
||||
except Exception as e:
|
||||
continue
|
||||
|
||||
print(f"\n📥 总共获取 {len(all_records)} 条流程实例")
|
||||
|
||||
# Step 3: 转换 formData
|
||||
# # Step 3: 转换 formData
|
||||
converted_records = []
|
||||
for inst in all_records:
|
||||
form_data = inst.get("formData", {})
|
||||
@@ -177,11 +184,15 @@ class GetYDData:
|
||||
converted_records.append(converted)
|
||||
|
||||
# Step 4: 保存
|
||||
if converted_records:
|
||||
df = pd.DataFrame(converted_records)
|
||||
if all_records:
|
||||
df = pd.DataFrame(all_records)
|
||||
output_path = os.path.join(output_dir, "converted_yd_data.csv")
|
||||
df.to_csv(output_path, index=False, encoding="utf_8_sig")
|
||||
print(f"\n✅ 成功保存 {len(converted_records)} 条记录至: {output_path}")
|
||||
df.to_csv(output_path, index=False)
|
||||
|
||||
df1 = pd.DataFrame(all_records_detils)
|
||||
output_path1 = os.path.join(output_dir, "converted_yd_data_detail.csv")
|
||||
df1.to_csv(output_path1, index=False)
|
||||
print(f"\n✅ 成功保存 {len(all_records)} 条记录至: {output_path}")
|
||||
else:
|
||||
print("\n❌ 无有效数据")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user