#!/usr/bin/env python3
"""Test Epoint API on guzhen.gov.cn"""
import requests, json

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
    'Referer': 'https://www.guzhen.gov.cn/zfxxgk/public/column/29641?type=4&catId=18193621&action=list&nav=3',
    'X-Requested-With': 'XMLHttpRequest',
}

# Try various API endpoints
apis = [
    '/c1/bengbu/publicInfoList_new2023',
    '/c1/bengbu/publicInfoList_new2020',
    '/c1/bengbu/publicInfolist_bm2025',
]

for api_path in apis:
    url = 'https://www.guzhen.gov.cn' + api_path
    params = {
        'pageSize': '10',
        'pageIndex': '1',
        'type': '4',
        'catId': '18193621',
        'organId': '29641',
        'siteId': '10930267',
    }
    try:
        r = requests.get(url, headers=headers, params=params, timeout=15)
        print('API %s: status=%d, len=%d' % (api_path, r.status_code, len(r.text)))
        print('  Response: %s...' % r.text[:300])
    except Exception as e:
        print('API %s: ERROR %s' % (api_path, e))

# Also try POST
for api_path in apis:
    url = 'https://www.guzhen.gov.cn' + api_path
    params = {
        'pageSize': '10',
        'pageIndex': '1',
        'type': '4',
        'catId': '18193621',
        'organId': '29641',
        'siteId': '10930267',
    }
    try:
        r = requests.post(url, headers=headers, data=params, timeout=15)
        print('POST %s: status=%d, len=%d' % (api_path, r.status_code, len(r.text)))
        if r.text:
            print('  Response: %s...' % r.text[:300])
    except Exception as e:
        print('POST %s: ERROR %s' % (api_path, e))
