# -*- coding: utf-8 -*-
"""检查 activities_feishu / daily_activities / mcp_orders_input 是否也在 CDN 上、线上版本是否落后于本地。"""
import json
import os
import urllib.parse
import urllib.request

BASE = 'https://bier-sales-d0gatbvlx288724e9-1458438710.tcloudbaseapp.com/'
D = os.path.expanduser('~/Desktop/Hermes输出-工作类/数据')

CANDIDATES = [
    ('数据/activities_feishu.json', 'activities_feishu.json'),
    ('数据/daily_activities_mcp.json', 'daily_activities_mcp.json'),
    ('数据/mcp_orders_input.json', 'mcp_orders_input.json'),
    ('数据/mcp_customers.json', 'mcp_customers.json'),
    ('数据/mcp_complaints.json', 'mcp_complaints.json'),
    ('数据/customer_360.json', 'customer_360.json'),
]

for remote_path, local_name in CANDIDATES:
    url = BASE + urllib.parse.quote(remote_path)
    try:
        req = urllib.request.Request(url, headers={'User-Agent': 'hermes-cron/1.0'})
        with urllib.request.urlopen(req, timeout=60) as r:
            body = r.read()
        try:
            d = json.loads(body.decode('utf-8'))
            stamp = d.get('updated') or d.get('updated_at') or d.get('generated') or d.get('_merged_at') or ''
        except Exception:
            stamp = '(非JSON或解析失败)'
        print('ONLINE %-26s %9d bytes  stamp=%s' % (local_name, len(body), stamp))
    except Exception as e:
        print('404/OFF %-24s %s' % (local_name, str(e)[:60]))
