Zum Inhalt

springer_open_pdf

Overview

The springer_open_pdf module downloads the PDF file for each Springer Nature article. Springer's JATS XML full-text does not include the image files that appear in the article, so the PDF is fetched separately to preserve them for archival. The URL for the PDF is not requested from Springer's search API directly — it is already present in the CrossRef metadata under the link field, in an entry whose intended-application is "text-mining" and whose content-type ends with pdf.

Module ordering: springer_open_pdf should run after springer_open. It requires metadata-article.json but processes each article independently — no batching, no daily quota, since the PDF URLs are direct download links and are not billed against the Springer API quota. If the CrossRef metadata does not contain a text-mining PDF link, the article is routed into a stop folder for manual review.

The module contains two primary Python files:

  1. flow.py
  2. tasks.py

flow.py

This file defines the main flow for Springer PDF harvesting. For each article, it extracts the text-mining PDF URL from the CrossRef metadata, then either downloads the PDF or creates a stop folder if no such URL is present.

springer_open_pdf()

  • Required Parameters:

  • name_of_config_file (str): Name of the configuration file. Default is "springer_pdf_lisa.json"

  • test_copy (bool): Flag to indicate if it is a test run. Default is True

  • Context for Use:

  • This function is the main entry point for the Springer PDF harvesting flow. It iterates over every article of every journal in the module context. For each article, it reads the CrossRef metadata, calls extract_text_mining_url to find the PDF URL, and dispatches to one of two paths: if no URL is found, the article is routed to a stop folder with an error message; otherwise, the PDF is downloaded into a pdf/ subfolder and a history.csv entry is written.

  • Example Usage:

  • python springer_open_pdf('springer_pdf_example.json', test_copy=False)

  • Example Output:

  • INFO: Module name: springer_open_pdf INFO: Set base path to: /mnt/nas/wdm-test INFO: Module context: [{'ISSN': '2948-2143', 'position': 3, 'previous_module': 'springer_open', ...}] INFO: Previous module: springer_open INFO: Downloading PDF from https://link.springer.com/content/pdf/10.1186%2Fs42467-023-00015-y.pdf INFO: PDF saved to /mnt/nas-tmp/.../temp-springer_open_pdf_2025-01-17/pdf/s42467-023-00015-y.pdf

    When no text-mining URL is present in the CrossRef metadata:
    
    WARNING: No field ['intended-application'] = 'text-mining' in the CrossRef file at: /mnt/.../metadata-article.json

tasks.py

This file contains the task definitions used in the Springer PDF harvesting flow. It handles finding the PDF URL in the CrossRef metadata, downloading the PDF file, and writing the appropriate history.csv and error CSV entries.

download_pdf()

  • Required Parameters:

  • url (str): The URL to download the PDF from

  • temp_current_module_dir (pathlib.Path): Path to the current temp module directory
  • filename (str): The file name for the downloaded PDF (usually <article_folder_name>.pdf)

  • Context for Use:

  • This is the main Prefect @task of the module. It creates a pdf/ subdirectory in the temp module directory (if not already present), makes a synchronous HTTPS GET request to the given URL, and writes the response bytes to pdf/<filename>. Raises requests.HTTPError on non-2xx responses so the flow can surface the failure.

  • Example Usage:

  • python pdf_path = download_pdf( text_mining_url, temp_current_module_dir, 's42467-023-00015-y.pdf', )

  • Example Output:

  • Returns the path to the written PDF, e.g. PosixPath('/mnt/.../temp-springer_open_pdf_2025-01-17/pdf/s42467-023-00015-y.pdf').

document_springer_open_pdf_error()

  • Required Parameters:

  • module_name (str): Name of the current module

  • latest_previous_module (pathlib.Path): Path to the latest previous module directory
  • error_message (str): error message

  • Context for Use:

  • Writes the error message to a springer_open_pdf_error.txt file inside the article directory, and also appends an entry to the central error CSV log. Called when the article's CrossRef metadata does not contain a text-mining PDF link (the article is then routed to a stop folder by the flow).

  • Example Usage:

  • python document_springer_open_pdf_error( module_name='springer_open_pdf', latest_previous_module=prev_module_path, error_message="No field ['intended-application'] = 'text-mining' in the CrossRef file at: ...", )


The lower-level helper functions in tasks.py are listed below.

extract_text_mining_url()

  • Required Parameters:

  • metadata_path (pathlib.Path): Path to metadata-article.json

  • Context for Use:

  • Iterates the CrossRef link field in metadata-article.json and returns the URL from the first entry whose intended-application equals "text-mining" and whose content-type ends with pdf. Returns None when no matching entry is found, in which case the caller creates a stop folder for that article. The content-type filter is important — some CrossRef link entries are text-mining but point to XML or other formats, and only the PDF variant is wanted here.

copy_previous_module_into_temp()

  • Required Parameters:

  • latest_previous_module (pathlib.Path): Path to the previous module directory

  • temp_current_module_dir (pathlib.Path): Path to the current temp module directory

  • Context for Use:

  • Copies the entire previous module folder as a named subfolder inside the current temp directory. Used only in the stop-folder path, so that when the stop folder is deleted in the future the previous module folder can be restored intact and the article can be reprocessed.