25 lines
926 B
TypeScript
25 lines
926 B
TypeScript
const KEY = process.env.NEIS_API_KEY;
|
|
|
|
export function removeNutritionInfo(value: string): string {
|
|
const lines = value.trim().split('\n');
|
|
const cleanedLines = lines.map(line => line.replace(/\(.*?\)/g, '').trim());
|
|
const result = cleanedLines.join('\n');
|
|
return result;
|
|
}
|
|
|
|
export async function getMealInfo(MLSV_YMD: string): Promise<{ meal: string; date: string, kcal: string }> {
|
|
const url = `https://open.neis.go.kr/hub/mealServiceDietInfo?Type=json&ATPT_OFCDC_SC_CODE=E10&SD_SCHUL_CODE=7331071&MLSV_YMD=${MLSV_YMD}&KEY=${KEY}`;
|
|
const response = await fetch(url);
|
|
const data = await response.json();
|
|
// @ts-ignore
|
|
const DDISH_NM = data.mealServiceDietInfo[1].row[0].DDISH_NM;
|
|
return {
|
|
meal: removeNutritionInfo(DDISH_NM.replace(/<br\s*\/?>/gi, '\n')),
|
|
date: MLSV_YMD,
|
|
// @ts-ignore
|
|
|
|
kcal: data.mealServiceDietInfo[1].row[0].CAL_INFO,
|
|
};
|
|
|
|
}
|
|
|