# -*- coding: utf-8 -*-
import json, os, shutil, datetime, sys
os.chdir(os.path.dirname(os.path.abspath(__file__)))

print('== verify cs_pools ==')
d = json.load(open('data/opportunity_goods.json', encoding='utf-8'))
print('collected_at:', d['collected_at'])
cp = d.get('cs_pools', {})
print('cs_pools keys:', list(cp.keys()))
for k, p in cp.items():
    print(k, 'raw', p.get('raw'), 'relevant', p.get('relevant'), 'excluded', p.get('excluded_n'),
          'time', p.get('capture_time'), 'top2', [(g['name'][:14], g['price']) for g in p.get('top_goods', [])[:2]])

print('== archive ==')
src_dir = '_scrape'
hist = os.path.join(src_dir, '历史', '20261009')
os.makedirs(hist, exist_ok=True)
files = ['cs_hot_goods.json', 'cs_short_goods.json', 'hot_sale.json', 'potential.json', 'favorite.json',
         'season_new.json', 'hot_follow.json', 'table.json', 'menu_counts.json',
         'search_hot_words.json', 'search_short_words.json', 'search_analysis.json']
for f in files:
    fp = os.path.join(src_dir, f)
    if os.path.exists(fp):
        shutil.copy2(fp, os.path.join(hist, f))
        print('archived', f)
    else:
        print('skip missing', f)
print('done')
