Downloader Module
GPC data downloading functionality.
This module provides classes for downloading GS1 GPC data from the GS1 API and finding the latest cached XML files.
The main class is GPCDownloader which handles downloading and locating GPC XML files. Legacy functions are provided for backward compatibility but new code should use the GPCDownloader class.
- class gs1_gpc.downloader.GPCDownloader(download_dir=None, language_code='en')[source]
Bases:
objectClass for downloading and managing GS1 GPC data files.
This class provides methods to download the latest GPC data from the GS1 API and find the latest cached XML files in a specified directory. It handles fallback mechanisms when downloads fail or when the gpcc library is not available.
- find_latest_xml_file()[source]
Find the latest GPC XML file in the download directory.
This method searches for XML files matching the pattern {language_code}-*.xml and returns the path to the file with the most recent version number. The version is extracted from the filename, which can be in either format: {language_code}-v{version}.xml or {language_code}-{version}.xml
- Returns:
Path to the latest XML file or None if no files found
- Return type:
- download_latest_gpc_xml()[source]
Download the latest GS1 GPC data in XML format.
This method attempts to download the latest GPC data using the gpcc library. If the download fails or if gpcc is not available, it falls back to using cached XML files. If no cached files are found, it uses the default fallback file.
The downloaded file is saved in the download directory with the naming convention: {language_code}-{version}.xml
- Returns:
Path to the XML file to use for import (either downloaded or cached)
- Return type:
- gs1_gpc.downloader.find_latest_xml_file(directory='/home/docs/checkouts/readthedocs.org/user_builds/gs1-gpc/checkouts/v0.3.3/data/imports', language_code='en')[source]
Find the latest GPC XML file in the specified directory.
This is a legacy function maintained for backward compatibility. New code should use the GPCDownloader class instead.
- gs1_gpc.downloader.download_latest_gpc_xml(language_code='en', target_directory=None)[source]
Download the latest GS1 GPC data in XML format.
This is a legacy function maintained for backward compatibility. New code should use the GPCDownloader class instead.
- Parameters:
language_code – Language code to download
target_directory – Optional directory where the XML file will be saved. If None, uses GPC_DOWNLOAD_DIR.
- Returns:
Path to the XML file to use for import
- Return type: