mirror of
https://github.com/geoadmin/service-geocat-upload.git
synced 2026-08-25 21:24:16 +00:00
Automatically harvest metadata records via a Python script | Read-only mirror of https://github.com/geoadmin/service-geocat-upload — Bundesamt für Landestopografie swisstopo. Issues & pull requests at the source.
- Python 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| docs | ||
| .gitignore | ||
| config.py | ||
| LICENSE | ||
| main.py | ||
| mkdocs.yml | ||
| README.md | ||
| upload_md.py | ||
geocat auotomatized upload Script
This project automates the upload of XML and MEF (.zip) metadata records to the geocat.ch (GeoNetwork) API.
Features
- 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.
Requirements
- 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)
Installation
-
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.
Usage
Simply run:
python main.py
The 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
Automation
On Linux
Use cron to run the script at regular intervals:
crontab -e
Add for example:
0 * * * * /usr/bin/python3 /path/to/main.py >> /path/to/cron.log 2>&1
On Windows
Use the Task Scheduler to run the script automatically (see Windows documentation).
Customization
- 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.
Project Structure
.
├── main.py
├── upload_md.py
├── config.py
├── .env
└── [XML/MEF folder]
Logging
Logs are displayed in the console. To redirect them to a file, run:
python main.py >> log.txt 2>&1
Authors
Script 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.