copernicus
Overview
The copernicus module processes full-text content delivered by the publisher Copernicus as .zip archives. Unlike the other publisher modules, Copernicus does not offer an API — content is delivered as pre-packaged zip files placed on the non-backed-up NAS, and the module's job is to locate the correct zip file for each article, unpack it, and sort its contents into xml/, pdf/, and images/ subfolders (Copernicus sometimes delivers supplementary images as PDF files, which are routed into images/ rather than pdf/).
The module also detects when full-text content for an article has already been harvested by an earlier previous-module version (e.g. after a metadata correction produced a new previous-module folder for an already-processed article), and skips reprocessing in that case.
Module ordering: copernicus should run after whichever metadata module (crossrefcrawler + validate_metadata) produces metadata-article.json, since the zip file location is derived from a PDF URL inside that metadata (ensure file exists at location).
The module contains two primary Python files:
flow.pytasks.py
flow.py
This file defines the main flow for Copernicus content processing using the Prefect library, and uses prefect's get_run_logger to log various stages along with the module context and previous module information. Compared to other modules, this flow does more of the case-handling directly inline (rather than delegating to tasks.py), including deciding whether a missing zip file should be retried later or marked as a permanent stop, based on the age of the article.
copernicus()
-
Required Parameters:
-
name_of_config_file(str): Name of the configuration file. Default is"copernicus.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 for the Copernicus processing flow. It iterates over every article of every journal in the module context. For each eligible article, it checks whether full text was already harvested under an earlier previous-module version (skipping if so), builds a
ZipFileInfofrom the article's CrossRef metadata, and callsextract_files_from_zipto unpack and sort the zip contents. Based on the returned error code, it either finalizes the article normally, retries later (if the zip is missing and the article is recent), or creates a stop folder (if the zip is missing and the article is old, or if the PDF/XML files are missing from the zip). -
Example Usage:
-
python copernicus('copernicus.json', test_copy=False) -
Example Output:
-
INFO: Module name: copernicus INFO: Set base path to: /mnt/...../copernicus INFO: Module context: [{'ISSN': '1867-1381', 'position': 2, 'previous_module': 'validate_metadata', ...}] INFO: Have to work on 1 journals INFO: Fetched full text for 8 out of 10 articles in journal: /mnt/.../1867-1381--2026-01-10-... INFO: 1 articles had updated metadata but full text already exists.WARNING: Zip file amt-2-401-2009.zip not foundWhen a zip file is missing for a recent article (retried on next run):ERROR: No zip file found for 1 articles. ERROR: List of articles for which no zipfile was found: ['amt-2-401-2009']WARNING: PDF file amt-2-401-2009.pdf not found in extracted contentsWhen PDF or XML is missing from an otherwise-found zip (always a stop):
tasks.py
This file contains the task definitions used in the Copernicus processing flow. It resolves the zip file location from CrossRef metadata, extracts and sorts the zip's contents, and writes error information when something goes wrong.
ZipFileInfo (class)
-
Constructor Parameters:
-
current_module_temp_dir(pathlib.Path): Path to the current temp module directory (currently unused inside the constructor, retained for interface consistency) -
metadata_path(pathlib.Path): Path tometadata-article.json -
Context for Use:
-
On construction, reads
metadata-article.jsonand collects candidate URLs fromresource.primary.URLand everylink[].URLentry. The first URL ending in.pdfis used to derive the zip file's base filename (the PDF filename without extension). From that base filename it builds the expected zip file location on the non-backed-up NAS, plus the expected XML and PDF file names and their eventual relative paths inside the article folder. RaisesValueErrorif no.pdf-suffixed URL is found in the metadata — this is not currently caught by the flow, so such an article will fail the flow run rather than being routed to a stop folder. -
Accessors:
get_zip_file_location(),get_xml_file_name(),get_xml_file_path(),get_pdf_file_name(),get_pdf_file_path() -
Example Usage:
-
python zip_info = ZipFileInfo(current_module_temp_dir, metadata_path) zip_info.get_zip_file_location() # PosixPath('/mnt/nas-tmp/wdm-test/Quelldaten_automatisiert_LOESCHEN/copernicus/amt-2-401-2009.zip')
extract_files_from_zip()
-
Required Parameters:
-
zip_info(ZipFileInfo): The resolved zip file info for the current article -
current_module_temp_dir(pathlib.Path): Path to the current temp module directory -
Context for Use:
-
This is the main Prefect
@taskand the workhorse of the module. It extracts the zip file into a temporaryunpack/folder, then walks the extracted contents to locate the expected PDF and XML file names. The PDF is moved intopdf/, the XML intoxml/, and every other extracted file intoimages/(this is where Copernicus's supplementary PDF-format images end up, since they don't match the expected PDF filename). The three folders are then moved into their final location directly undercurrent_module_temp_dir, and the temporaryunpack/folder is removed. Returns a tuple whose first two elements are always(success: bool, error_code: ErrorCode); when the PDF or XML file was missing, two additional boolean elements are appended indicating which file was missing. -
Example Usage:
-
python result = extract_files_from_zip(zip_info, current_module_temp_dir) is_successful = result[0] error_code = result[1] -
Example Output:
-
On success:
(True, ErrorCode.NoError) - On zip file not found:
(False, ErrorCode.ZipFileNotFound) - On missing PDF and/or XML inside an otherwise-found zip:
(False, ErrorCode.PdfOrXmlFileMissing, pdf_file_missing, xml_file_missing)
document_copernicus_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 or list): Human-readable error message(s) -
Context for Use:
-
Writes the error message to a
copernicus_error.txtfile in the article directory, and also appends an entry to the central error CSV log. Accepts either a single string or a list of strings; lists are newline-joined before being written. Called both when the zip file is missing (regardless of whether the article is retried or marked as a permanent stop) and when the PDF/XML extraction is incomplete. -
Example Usage:
-
python document_copernicus_error( module_name='copernicus', latest_previous_module=prev_module_path, error_message=['Zip file not found: /mnt/.../amt-2-401-2009.zip', 'Article amt-2-401-2009 is older than one year. Marking as STOP.'] )
The lower-level helper functions in tasks.py are listed below.
get_copernicus_download_root()
-
Context for Use:
-
Returns the path to the Copernicus zip delivery folder on the non-backed-up NAS:
<data_root_not_backed_up>/<DOWNLOADED_DATA_DIRECTORY>/copernicus. This is where the module expects to find the publisher's delivered zip files.
is_full_text_already_harvested()
-
Required Parameters:
-
module_name(str): Name of the current module previous_module(str): Name of the previous module-
article_dir_path(pathlib.Path): Path to the article directory -
Context for Use:
-
Checks whether any previous-module version of this article (not just the latest one) already carries a
processed-by-module-copernicusindicator. This handles the case where a metadata correction produced a newer previous-module folder for an article whose full text had already been successfully harvested under an older previous-module folder — the flow uses this to skip redundant re-downloading of unchanged full-text content.
ErrorCode (enum)
-
Values:
-
NoError = -1 ZipFileNotFound = 0-
PdfOrXmlFileMissing = 1 -
Context for Use:
-
Used as the second element of the tuple returned by
extract_files_from_zipto indicate the outcome. The flow branches on this value to decide whether to retry, stop, or finalize the article.