()
| 197 | |
| 198 | |
| 199 | def main(): |
| 200 | parser = argparse.ArgumentParser(description="Export Daily Data") |
| 201 | parser.add_argument("--input-dir", type=str, required=True, help="模拟输出目录") |
| 202 | parser.add_argument("--output-dir", type=str, default=None, help="导出输出目录") |
| 203 | parser.add_argument("--start-date", type=str, default=None, help="开始日期 YYYY-MM-DD") |
| 204 | parser.add_argument("--end-date", type=str, default=None, help="结束日期 YYYY-MM-DD") |
| 205 | parser.add_argument("--format", type=str, choices=["csv", "jsonl"], default="csv", help="输出格式") |
| 206 | args = parser.parse_args() |
| 207 | |
| 208 | input_dir = Path(args.input_dir) |
| 209 | if not input_dir.is_absolute(): |
| 210 | input_dir = PROJECT_ROOT / input_dir |
| 211 | |
| 212 | output_dir = args.output_dir |
| 213 | if output_dir: |
| 214 | output_dir = Path(output_dir) |
| 215 | if not output_dir.is_absolute(): |
| 216 | output_dir = PROJECT_ROOT / output_dir |
| 217 | else: |
| 218 | output_dir = input_dir / "exports" |
| 219 | output_dir.mkdir(parents=True, exist_ok=True) |
| 220 | |
| 221 | print(f"Input: {input_dir}") |
| 222 | print(f"Output: {output_dir}") |
| 223 | print(f"Date range: {args.start_date or 'start'} to {args.end_date or 'end'}") |
| 224 | print() |
| 225 | |
| 226 | export_func = export_to_csv if args.format == "csv" else export_to_jsonl |
| 227 | |
| 228 | # 导出 Profile History |
| 229 | print("Exporting profile history...") |
| 230 | profile_records = load_jsonl_file(input_dir, "", "profiles.jsonl", args.start_date, args.end_date) |
| 231 | export_func(profile_records, output_dir / "profile_history.csv" if args.format == "csv" else output_dir / "profile_history.jsonl", flatten_profile) |
| 232 | |
| 233 | # 导出 Episode History |
| 234 | print("Exporting episode history...") |
| 235 | episode_records = load_jsonl_file(input_dir, "", "episodes.jsonl", args.start_date, args.end_date) |
| 236 | export_func(episode_records, output_dir / "episode_history.csv" if args.format == "csv" else output_dir / "episode_history.jsonl", flatten_episode) |
| 237 | |
| 238 | # 导出 Drift Events |
| 239 | print("Exporting drift events...") |
| 240 | drift_records = load_jsonl_file(input_dir, "", "drift_timeline.jsonl", args.start_date, args.end_date) |
| 241 | export_func(drift_records, output_dir / "drift_events.csv" if args.format == "csv" else output_dir / "drift_events.jsonl", flatten_drift) |
| 242 | |
| 243 | # 导出 Paper Pools |
| 244 | print("Exporting paper pools...") |
| 245 | paper_pool_records = load_jsonl_file(input_dir, "", "paper_pools.jsonl", args.start_date, args.end_date) |
| 246 | if args.format == "csv": |
| 247 | export_func(paper_pool_records, output_dir / "paper_pools.csv", None) |
| 248 | else: |
| 249 | with (output_dir / "paper_pools.jsonl").open("w", encoding="utf-8") as f: |
| 250 | for r in paper_pool_records: |
| 251 | f.write(json.dumps(r, ensure_ascii=False) + "\n") |
| 252 | print(f" Exported {len(paper_pool_records)} records to paper_pools.jsonl") |
| 253 | |
| 254 | # 导出用户元数据 |
| 255 | print("Exporting user metadata...") |
| 256 | users_file = input_dir / "users.json" |
no test coverage detected