|
5 | 5 |
|
6 | 6 | This implementation uses Zenodo's REST API instead of OAI-PMH for more reliable |
7 | 7 | license detection. Benefits include: |
8 | | -- Structured license data (metadata.license.id) |
| 8 | +- Structured license data (metadata.license.id) |
9 | 9 | - Clear separation of access rights |
10 | | -- JSON parsing |
| 10 | +- JSON parsing |
11 | 11 | - Standardized license identifiers |
12 | 12 | """ |
13 | 13 | # Standard library |
|
57 | 57 | # CC License mapping for Zenodo API |
58 | 58 | cc_license_mapping = { |
59 | 59 | "cc-by": "CC BY 4.0", |
60 | | - "cc-by-sa": "CC BY-SA 4.0", |
| 60 | + "cc-by-sa": "CC BY-SA 4.0", |
61 | 61 | "cc-by-nc": "CC BY-NC 4.0", |
62 | 62 | "cc-by-nd": "CC BY-ND 4.0", |
63 | 63 | "cc-by-nc-sa": "CC BY-NC-SA 4.0", |
@@ -237,17 +237,17 @@ def classify_license(license_data): |
237 | 237 | # Special cases that need custom mapping |
238 | 238 | special_cases = { |
239 | 239 | "cc-zero": "CC0", |
240 | | - "cc0-1.0": "CC0", |
| 240 | + "cc0-1.0": "CC0", |
241 | 241 | "cc0": "CC0", |
242 | 242 | "cc-nc": "CC BY-NC 4.0", |
243 | | - "cc-nd": "CC BY-ND 4.0", |
| 243 | + "cc-nd": "CC BY-ND 4.0", |
244 | 244 | "cc-sa": "CC BY-SA 4.0", |
245 | 245 | "cc-publicdomain": "Public Domain Mark 1.0", |
246 | 246 | } |
247 | | - |
| 247 | + |
248 | 248 | if license_id in special_cases: |
249 | 249 | return special_cases[license_id] |
250 | | - |
| 250 | + |
251 | 251 | # Normalize standard CC licenses: cc-by-4.0 -> CC BY 4.0 |
252 | 252 | if license_id.startswith("cc-by"): |
253 | 253 | return license_id.upper().replace("-", " ") |
@@ -281,16 +281,17 @@ def fetch_zenodo_records(session, page=1, size=100, query="*"): |
281 | 281 | } |
282 | 282 |
|
283 | 283 | try: |
284 | | - response = session.get( |
285 | | - ZENODO_API_BASE_URL, params=params, timeout=15 |
286 | | - ) |
| 284 | + response = session.get(ZENODO_API_BASE_URL, params=params, timeout=15) |
287 | 285 | response.raise_for_status() |
288 | 286 | return response.json() |
289 | 287 | except requests.RequestException as e: |
290 | | - raise shared.QuantifyingException(f"Error fetching Zenodo records: {e}") |
| 288 | + raise shared.QuantifyingException( |
| 289 | + f"Error fetching Zenodo records: {e}" |
| 290 | + ) |
291 | 291 | except json.JSONDecodeError as e: |
292 | 292 | raise shared.QuantifyingException(f"Error parsing JSON response: {e}") |
293 | 293 |
|
| 294 | + |
294 | 295 | def extract_record_info(record_json): |
295 | 296 | """ |
296 | 297 | Extract information from a Zenodo REST API record. |
@@ -413,7 +414,9 @@ def main(): |
413 | 414 | session, page=page, size=records_per_page, query=query |
414 | 415 | ) |
415 | 416 | except (requests.RequestException, json.JSONDecodeError) as e: |
416 | | - raise shared.QuantifyingException(f"Failed to fetch Zenodo records: {e}") |
| 417 | + raise shared.QuantifyingException( |
| 418 | + f"Failed to fetch Zenodo records: {e}" |
| 419 | + ) |
417 | 420 |
|
418 | 421 | if not response_data or "hits" not in response_data: |
419 | 422 | raise shared.QuantifyingException( |
|
0 commit comments