frontiers
Overview
The frontiers module retrieves full-text content for Frontiers-published articles from a Frontiers-operated FTP server. It computes each article's expected zip filename prefix from its DOI and volume (e.g. frobt-02-1234567), connects to the FTP server once per flow run, finds all zip files matching that prefix (Frontiers may publish multiple versions of the same package over time; the module picks the natural-sort-highest one (this matters because Frontiers sometimes republishes an article's package multiple times, and the filenames usually differ by a version-like number)), downloads and unpacks the zip, and sorts the extracted files into pdf/, xml/, image/, and supplement/ subfolders based on file extension and exact-filename matching against the expected full-text file names.
A companion module, frontiers_delete_stop_folders, co-exists with this module to handle the stop_folders. The companion module is a manual, separately-triggered step (it requires an explicit ISSN list). See the frontiers_delete_stop_folders module documentation for details.
Module ordering: frontiers should run after metadata-article.json has been created, and its own connection setup / FTP credentials are read from the shared harvesting config JSON. It should be followed by the frontiers_delete_stop_folders module.
The module contains two primary Python files:
flow.pytasks.py
flow.py
This file defines the main flow for Frontiers full-text retrieval using the Prefect library. The FTP connection and the full file listing (ftp.nlst()) are established once at the start of the whole flow run (before iterating any journal or article), and reused for every journal and article processed during that run; the connection is only closed (ftp.quit()) after all journals have been processed.
frontiers()
-
Required Parameters:
-
name_of_config_file(str): Name of the configuration file. Default is"frontiers_test.json" -
test_copy(bool): Flag to indicate if it is a test run. Default isFalse -
Context for Use:
-
This function is the main entry point. It reads FTP credentials from the shared harvesting config (
tasks.read_config), opens one FTP connection and lists all files on the server once, then iterates every article of every journal in the module context. For each eligible article, it computes the expected zip filename prefix from the DOI and volume inmetadata-article.json, finds all matching zip files already listed from the server, selects the natural-sort-highest one, downloads it, extracts its contents, and sorts each extracted file into the appropriate subfolder. Ahistory.csventry is written for every processed article. The FTP connection is closed only once, after the entire flow completes. -
Example Usage:
-
python frontiers('frontiers_test.json', test_copy=False) -
Example Output:
-
INFO: Module name: frontiers INFO: Set base path to: /mnt/.../wdm-test INFO: Module context: [{'ISSN': '2813-4168', 'position': 2, 'previous_module': 'validate_metadata', ...}] INFO: Start Frontiers full text retrieval for ISSN: 2813-4168. INFO: Journal path: /mnt/.../2813-4168--2026-01-10-... All Zip Files which contain the folder base name: ['frpro-02-1663791.zip'] INFO: prefix_sorted: ['frpro-02-1663791'] INFO: ZIP_FILE_NAME: frpro-02-1663791.zip INFO: ZIP-Datei wurde gespeichert unter: /mnt/.../temp-frontiers_2025-01-17/frpro-02-1663791.zipWARNING: no zip file found for the following folder_basename: frpro-02-9999999When no matching zip file exists on the server:WARNING: Volltext PDF fehlt: /mnt/.../unpack WARNING: Volltext XML fehlt: /mnt/.../unpackWhen the expected PDF or XML full text is missing from the unpacked zip:
tasks.py
This file contains the helper functions used by the Frontiers flow: reading FTP credentials, writing the module's error CSV and per-article error text file, and building the individual error-row dictionaries for the various failure cases (unknown file type, missing zip, missing full-text PDF/XML, empty folder).
read_config()
-
Required Parameters:
-
file_path(str or Path): Path to the shared harvesting config JSON -
Context for Use:
-
Reads
frontiers_ftp_url,frontiers_ftp_username, andfrontiers_ftp_passwordfrom the given config file and returns them as a(url, username, password)tuple. OnFileNotFoundErrororjson.JSONDecodeError,it returns(None, None, None), which would result in the caller inflow.pyraising anftpliberror.
document_frontiers_error()
-
Required Parameters:
-
module_name(str): Name of the current module latest_previous_module(Path): Path to the latest previous module directory-
error_message(str or list): The error message(s) to record -
Context for Use:
-
Writes a
frontiers_error.txtfile summarizing the article's processing error(s), via_normalize_frontiers_error_message. The function probes for the correct destination directory: it first checks whether the current temp module directory still exists (writes there if so), otherwise checks whether the permanent stop-processing directory already exists (writes there if so), and falls back to the article's parent directory as a last resort.
write_frontiers_errors_csv()
-
Required Parameters:
-
error_data_list(list): List of error-row dicts to append -
Context for Use:
-
Appends rows to the module's persistent CSV error log, creating the file (with header) if it doesn't already exist.
error_message_missing_zip() / error_message_unbekannter_Dateityp() / error_message_Volltext_PDF_fehlt() / error_message_Volltext_XML_fehlt() / error_message_empty_folder()
-
Context for Use:
-
Each function builds one error-row dict (matching the
LOG_FILE_FRONTIERS_ERRORScolumn schema:date,file_ending,file_name,error_message,file_path,issn) for a specific failure case, logs a warning, and appends the row to the caller'serror_data_list.error_message_missing_zipcovers no matching zip found on the FTP server;error_message_unbekannter_Dateitypcovers an unpacked file whose extension isn't recognized;error_message_Volltext_PDF_fehlt/_XML_fehltcover a missing full-text PDF/XML after unpacking;error_message_empty_foldercovers an empty folder entry inside the zip.
The lower-level helper functions in tasks.py are listed below.
_normalize_frontiers_error_message()
-
Required Parameters:
-
error_message(str, list, or None) -
Context for Use:
-
Converts the various shapes
error_messagecan take (a plain string, a list of error-row dicts, orNone) into either a single display string or a list of display strings, used bydocument_frontiers_errorbefore writing tofrontiers_error.txt. When given a list of dicts, it prefers combining theerror_messageandfile_pathfields into one readable line per entry.