Spaces:
Sleeping
Sleeping
| """Verify the CORE API key is accepted and shows the lifted rate limit. | |
| Bypasses the disk cache (unique query) so we test the live authenticated call. | |
| """ | |
| import os | |
| import sys | |
| import time | |
| import requests | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from plagdetect.oasources import _load_core_key | |
| key = _load_core_key() | |
| print("key loaded:", (key[:4] + "β¦" + key[-3:]) if key else "NONE") | |
| q = f"transformer attention {int(time.time())}" # unique -> not cached | |
| url = f"https://api.core.ac.uk/v3/search/works?q=machine+learning&limit=3" | |
| headers = {"Authorization": f"Bearer {key}", "User-Agent": "plagcheck-edu/0.1"} | |
| r = requests.get(url, headers=headers, timeout=30) | |
| print("HTTP:", r.status_code) | |
| # CORE returns rate-limit headers β these prove the key tier | |
| for h in ("X-RateLimit-Limit", "X-RateLimitRemaining", "X-RateLimit-Remaining", | |
| "X-RateLimitRetryAfter"): | |
| if h in r.headers: | |
| print(f" {h}: {r.headers[h]}") | |
| if r.ok: | |
| d = r.json() | |
| print("totalHits:", d.get("totalHits")) | |
| print("results:", len(d.get("results", []))) | |
| if d.get("results"): | |
| print("sample:", d["results"][0].get("title", "")[:60]) | |
| print("\nCORE KEY WORKS β authenticated, higher limit active") | |
| else: | |
| print("body:", r.text[:200]) | |