- Add lunar calendar astronomical calculation engine (lunar_calendar.py) - Add converter utilities for solar/lunar date conversion - Add historical era name conversions (chrono_converter.py, converter_with_eras.py) - Add FastAPI REST API for date conversion services - Add age calculator using lunar calendar - Add batch generation script for lunar calendar JSON data - Add project documentation (CLAUDE.md, pyproject.toml) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
30 lines
863 B
Python
30 lines
863 B
Python
import os
|
|
from multiprocessing import Pool
|
|
from pathlib import Path
|
|
from lunar_calendar import LunarCalendar
|
|
|
|
def process_year(year, output_dir):
|
|
try:
|
|
cal = LunarCalendar(year)
|
|
out_file = output_dir / f"{year}.json"
|
|
# 如果不想覆寫,再加個 exists() 檢查
|
|
if not out_file.exists():
|
|
cal.save_json(str(out_file))
|
|
print(f"完成,已輸出:{out_file}")
|
|
else:
|
|
print(f"跳過,檔案已存在:{out_file}")
|
|
except Exception as e:
|
|
print(f"處理 {year} 時出錯:{e}")
|
|
|
|
def main():
|
|
output_dir = Path('lunar_json')
|
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
# years = range(1851, 2149)
|
|
years = range(1, 2149)
|
|
with Pool() as pool:
|
|
pool.starmap(process_year, [(y, output_dir) for y in years])
|
|
|
|
if __name__ == "__main__":
|
|
main()
|