This project automates the upload of XML and MEF (.zip) metadata records to the geocat.ch (GeoNetwork) API.
- Authenticates to the geocat API using username and password.
- Automatically uploads all
.xmland.zip(MEF) files from a specified folder to the API. - For MEF files, can validate and/or publish the metadata after upload, depending on parameters.
- Detailed logging of operations and errors.
- Python 3.8+
- A geocat.ch user account with write permissions on the target group.
- Python dependencies:
requestspython-dotenv(if you use a.envfile for credentials)
-
Clone the repository or copy the files into a folder.
-
Install dependencies:
pip install requests python-dotenv
-
Configure parameters in
config.pyand.env:.env:GEOCAT_USERNAME=your_username GEOCAT_PASSWORD=your_password PROXY_HTTP= PROXY_HTTPS=config.py: adjust paths, group, and other parameters as needed.
-
Place your XML and MEF files to upload in the folder defined by
PATH_TO_MD_FILESinconfig.py.
Simply run:
python main.pyThe script will:
- Check if the target folder exists.
- Authenticate the user.
- Upload each
.xmlfile as metadata. - Upload each
.zipfile as MEF, then:- Validate the metadata if
PARAMETER_VALIDATIONis set to"True". - Publish the metadata if
PARAMETER_PUBLICATIONis set to"True".
- Validate the metadata if
Use cron to run the script at regular intervals:
crontab -eAdd for example:
0 * * * * /usr/bin/python3 /path/to/main.py >> /path/to/cron.log 2>&1
Use the Task Scheduler to run the script automatically (see Windows documentation).
- Target group: edit
PARAMETER_GROUPinconfig.py. - Upload parameters: adjust
PARAMETER_VALIDATIONandPARAMETER_PUBLICATIONinconfig.pyto control MEF validation and publication. - Proxy settings: leave
PROXY_HTTPandPROXY_HTTPSempty if not needed.
.
├── main.py
├── upload_md.py
├── config.py
├── .env
└── [XML/MEF folder]
Logs are displayed in the console. To redirect them to a file, run:
python main.py >> log.txt 2>&1Script adapted and automated for geocat.ch by swisstopo.
Note:
- The script will process all
.xmland.zipfiles in the target folder. - For MEF files, validation and publication are controlled by the parameters in
config.py. - Make sure your user has the necessary permissions on the target group.