2.1 KiB
Serienbrief
Using this script it is possible to generate form letters from a template and an SQL query.
A template file with some placeholder variables is required and an SQL query to be executed against a MariaDB/MySQL database. The column names from the query correspond to the variable names in the template.
The template is processed using the Cheetah template (https://cheetahtemplate.org/) module, so simple variable placeholder are just the variable name prefixed with the dollar-sign.
However, all other Cheetah template language elements, like conditions, are also available.
The script will generate one output file for each row from the result of the database query.
Usage
usage: serienbrief [-h] [--config CONFIG] [--queryFile QUERYFILE]
[--templateFile TEMPLATEFILE] [--outputPrefix OUTPUTPREFIX]
[--outputSuffix OUTPUTSUFFIX] [--verbose]
Serienbrief
optional arguments:
-h, --help show this help message and exit
--config CONFIG, -f CONFIG
Config file, default is $pwd/serienbrief.ini
--queryFile QUERYFILE, -q QUERYFILE
query file, default is $pwd/serienbrief.sql
--templateFile TEMPLATEFILE, -t TEMPLATEFILE
template file, default is $pwd/serienbrief.tmpl
--outputPrefix OUTPUTPREFIX, -p OUTPUTPREFIX
prefix for the output file, will be extended by an
auto increment number
--outputSuffix OUTPUTSUFFIX, -s OUTPUTSUFFIX
suffix for the output file
--verbose, -v verbose output
Config file
The configuration file at least requires the database section. However, the options queryFile, templateFile, outputPrefix and outputSuffix can also be set using the configuration file.
[database]
host = 172.16.10.18
user = serienbrief
pass = test123
name = serienbrieftest
[config]
queryFile = example.sql
templateFile = example.tmpl
outputPrefix = brief
outputSuffix = tex
Required modules
- Python 3
- mariadb
- cheetah3