补全9月11日至13日课评:为13名学生创建请假文档,为5个班级创建总结文档
This commit is contained in:
62
.claude/memory/temp/oj_probe.py
Normal file
62
.claude/memory/temp/oj_probe.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Probe OJ: login, list records for lesson-01 tid, and test whether a single
|
||||
record exposes the submission code. Prints discoveries."""
|
||||
import io, sys, re, json, httpx
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace')
|
||||
from pathlib import Path
|
||||
|
||||
env = {}
|
||||
for line in (Path('.env')).read_text(encoding='utf-8').split('\n'):
|
||||
line = line.strip()
|
||||
if line and not line.startswith('#') and '=' in line:
|
||||
k, v = line.split('=', 1)
|
||||
env[k] = v
|
||||
|
||||
base = env.get('OJ_BASE_URL', 'https://oj.qonnwolf.com')
|
||||
TID = '6a8c6a8b8499477a04169f85' # CSP04 lesson 01 基础回顾
|
||||
|
||||
client = httpx.Client(base_url=base, follow_redirects=True, timeout=30)
|
||||
r = client.post('/login', json={'uname': env.get('OJ_USERNAME'), 'password': env.get('OJ_PASSWORD')})
|
||||
ok = any(c.name == 'sid' for c in client.cookies.jar)
|
||||
print('LOGIN:', 'OK' if ok else 'FAIL', 'status', r.status_code)
|
||||
if not ok:
|
||||
raise SystemExit('login failed')
|
||||
|
||||
# 1. record list via JSON API
|
||||
r = client.get(f'/d/system/record?tid={TID}&page=1', headers={'Accept': 'application/json'})
|
||||
print('RECORD LIST status', r.status_code)
|
||||
try:
|
||||
data = r.json()
|
||||
except Exception as e:
|
||||
print('NOT JSON:', r.text[:300])
|
||||
data = {}
|
||||
rdocs = data.get('rdocs', [])
|
||||
print('rdocs count', len(rdocs))
|
||||
if rdocs:
|
||||
rec = rdocs[0]
|
||||
print('RECORD KEYS:', sorted(rec.keys()))
|
||||
for k in ('_id','uid','pid','score','status','judgeAt','code'):
|
||||
print(' ', k, '=', repr(rec.get(k))[:80])
|
||||
# pick the record that has a code-like field or pick any
|
||||
sample = rec
|
||||
rid = sample.get('_id')
|
||||
print('USING rid =', rid, 'pid =', sample.get('pid'))
|
||||
# 2. try single-record detail endpoints
|
||||
for ep in (f'/d/system/record/{rid}', f'/record/{rid}', f'/d/system/submission/{rid}'):
|
||||
try:
|
||||
rr = client.get(ep, headers={'Accept': 'application/json'})
|
||||
txt = rr.text
|
||||
has_code = 'code' in txt or '"code"' in txt
|
||||
print(f'DETAIL {ep} status={rr.status_code} has_code_field={has_code} len={len(txt)}')
|
||||
try:
|
||||
j = rr.json()
|
||||
keys = sorted(j.keys()) if isinstance(j, dict) else 'list'
|
||||
print(' detail keys:', keys if isinstance(keys, list) else keys)
|
||||
if isinstance(j, dict) and 'code' in j:
|
||||
print(' CODE snippet:', repr(j['code'])[:200])
|
||||
except Exception:
|
||||
print(' (not json) snippet:', txt[:160].replace('\n',' '))
|
||||
except Exception as e:
|
||||
print(' DETAIL err', ep, e)
|
||||
client.close()
|
||||
Reference in New Issue
Block a user