Add MAGIC scraper - #14
Draft
MrKoga wants to merge 2 commits into
Draft
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Adds a MAGIC scraper — the MAGICapp platform — to the datasets scraping pipeline, same shape as the NICE scraper: discovery and extraction are separate, and everything outputs a normalized
ScrapedDocument.MAGICapp (https://app.magicapp.org) is a publishing platform for GRADE clinical practice guidelines, so one source covers many institutions — 85 publishing organisations, 50 with English guidelines, including the WHO, the European Stroke Organisation and Cancer Council Australia. About 233 English guidelines today.
Meditron lists MAGIC as a source; its scraper drives the single-page app with Selenium and is marked
UNTESTEDin the source. MAGICapp has a public unauthenticated JSON API, so this replaces that approach rather than porting it.How it works
GET https://api.magicapp.org/api/v1/guidelinesreturns the whole catalogue in one response; each entry'sjsonPathpoints at the full guideline as structured JSON.languages=("en",)), as a default rather than a policy — happy to change it, drop it, or expose a flag.A few behaviors worth knowing, one line each:
strength: "INFO"objects are editorial callout boxes, not recommendations — emitted as plain content, never labelled.POSSIBLY_OUTDATEDare skipped (2 in the catalogue).http://catalogue URLs are upgraded to HTTPS (the file host 403s plain HTTP).metadatacarries bothguideline_idandpublished_id; version-pinned viewer URLs need the latter.Shared-helper change included
The first commit adds an opt-in
drop_imagestohtml_to_markdown— defaultFalse, so NICE output is byte-for-byte unchanged; MAGIC passesTruebecause MAGICapp inlines figures as base64 data URIs (53.9% of emitted characters across a 63-guideline sample). The same commit hardens fragment re-serialization to keep text sitting before a fragment's first tag. Happy to split that commit into its own PR if you prefer shared-code changes reviewed separately.CLI
--documentsis an upper bound on a catalogue run: unreadable or placeholder guidelines are logged and skipped.Files
datasets/amfv_datasets/scraping/magic.py— scraper moduledatasets/amfv_datasets/scraping/cli.py—--source magicdispatchdatasets/amfv_datasets/scraping/__init__.py— public namesdatasets/test/test_scraping_magic.py— offline tests,MockTransport, no fixture filesdatasets/amfv_datasets/scraping/html.py+datasets/test/test_scraping_html.py— the shared-helper commit aboveTest plan
uv run pytest datasets/test— 66 passed, no regressionsuv run ruff check datasets/ && uv run ruff format --check datasets/--documents 3, non-empty markdown, no embedded image datauv run amfv-scrape --source magic --documents 3 -f markdown -o /tmp/magic-out/🤖 Generated with Claude Code