2021-01-23 21:55:03 +01:00
2021-01-23 21:55:03 +01:00
2021-01-23 21:55:03 +01:00
2021-01-23 22:11:52 +01:00
2021-01-23 22:10:17 +01:00
2021-01-23 21:55:03 +01:00

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 = hv-serienbrief
pass = test123
name = hausverwaltung

[config]
queryFile = example.sql
templateFile = example.tmpl
outputPrefix = jahresabrechnung
outputSuffix = tex

Required modules

  • Python 3
  • mariadb
  • cheetah3
Description
No description provided
Readme 36 KiB
Languages
Python 100%