File size: 1,297 Bytes
ebebfe8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""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])