UNPKG

@xzkcz/iztro-mcp-server

Version:

MCP server exposing iztro astrology methods for Zi Wei Dou Shu astrolabe generation and horoscope analysis

44 lines 1.79 kB
import { existsSync, mkdirSync, writeFileSync } from "fs"; import { join } from "path"; import { getAstroYear } from "./getAstroYear.js"; import { getAstroMonth } from "./getAstroMonth.js"; import { getCircularReplacer } from "./utils/getCircularReplacer.js"; import { hourToTimeIndex } from "./utils/hourToTimeIndex.js"; export function genAndSaveAstrolabe(options) { const { date, hour, gender, path, fixLeap = true, locale = 'zh-CN' } = options; // Ensure directory exists if (!existsSync(path)) { mkdirSync(path, { recursive: true }); } const timeIndex = hourToTimeIndex(hour); const result = getAstroYear({ solarBirthDate: date, timeIndex, gender, fixLeap, locale }); const { astrolabe, decadePeriods, agePeriods, yearPeriods } = result; // Get month periods for current year const currentYear = new Date().getFullYear(); const monthPeriods = getAstroMonth({ year: currentYear, fixLeap, locale }); // Save astrolabe.json writeFileSync(join(path, 'astrolabe.json'), JSON.stringify(astrolabe, getCircularReplacer(), 2)); // Save decades.json writeFileSync(join(path, 'decades.json'), JSON.stringify(decadePeriods, null, 2)); // Save ages.json writeFileSync(join(path, 'ages.json'), JSON.stringify(agePeriods, null, 2)); // Save years.json writeFileSync(join(path, 'years.json'), JSON.stringify(yearPeriods, null, 2)); // Save months.json writeFileSync(join(path, 'months.json'), JSON.stringify(monthPeriods, null, 2)); return { success: true, files: ['astrolabe.json', 'decades.json', 'ages.json', 'years.json', 'months.json'].map(f => join(path, f)) }; } //# sourceMappingURL=genAndSaveAstrolabe.js.map