feat: 최근 14일 안에 쓴 무신사 스냅은 다시 고르지 않음(out/snap-history.json)

This commit is contained in:
minaChoi committed 2026-10-26 11:32:03 +09:00
1 parent e1b5efc01b
commit 928e9053cf
1 file changed
+24 -3
+24 -3
View File
@@ -1,7 +1,23 @@
// 무신사 스냅(공개 API)에서 오늘 날씨에 맞는 인기 코디를 사람별로 하나씩 고른다. 사진·상품 썸네일은 그림 참고용으로만 내려받고 어디에도 올리지 않는다.
// 사용(확인용): node scripts/snap.mjs --band mild --out out/2026-10-26/snaps
import { mkdirSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { join, resolve } from 'node:path'
// 최근에 쓴 스냅은 다시 고르지 않는다 (스타일이 달라도 같은 코디가 또 나오지 않게)
const HISTORY_FILE = resolve('out/snap-history.json')
const HISTORY_DAYS = 14
function loadHistory() {
if (!existsSync(HISTORY_FILE)) return {}
try {
return JSON.parse(readFileSync(HISTORY_FILE, 'utf8'))
} catch {
return {}
}
}
function recentIds(history) {
const cutoff = Date.now() - HISTORY_DAYS * 86400_000
return new Set(Object.entries(history).filter(([day]) => new Date(day).getTime() >= cutoff).flatMap(([, ids]) => ids))
}
const LIST_URL = 'https://content.musinsa.com/api2/content/snap/v1/snaps'
const GOODS_URL = (no) => `https://goods-detail.musinsa.com/api2/goods/${no}`
@@ -161,7 +177,8 @@ export async function pickSnaps({ band, style, outDir, pages = 2, log = console.
log(`무신사 스냅 후보 ${pool.size}개 (구간 ${band}${styleTags.length ? ` · 스타일 #${styleTags.join(' #')} ${[...pool.values()].filter(hasStyle).length}개` : ''}). 상품 정보를 받아 거르는 중…`)
const picks = {}
const used = new Set()
const history = loadHistory()
const used = recentIds(history)
// 40대~ 를 먼저 골라야 단정한 코디가 남는다. 좋아요 순으로 상품 정보를 받아 보며 맞는 첫 코디를 고른다
for (const persona of ['f40', 'm40', 'f20', 'm20']) {
const { gender } = PERSONAS[persona]
@@ -200,6 +217,10 @@ export async function pickSnaps({ band, style, outDir, pages = 2, log = console.
log(` ${persona}: ${best.url} ♥${best.likes}${styleTags.length && !hasStyle(best) ? ' (스타일 태그 없음, 대체)' : ''} #${best.tags.slice(0, 3).join(' #')} | ${best.goods.map((g) => g.name).join(' / ').slice(0, 90)}`)
}
writeFileSync(join(outDir, 'picks.json'), JSON.stringify(picks, null, 1))
const today = new Date(Date.now() + 9 * 3600_000).toISOString().slice(0, 10)
history[today] = [...new Set([...(history[today] ?? []), ...Object.values(picks).map((p) => p.id)])]
mkdirSync(resolve('out'), { recursive: true })
writeFileSync(HISTORY_FILE, JSON.stringify(history, null, 1))
return picks
}