This commit is contained in:
2021-02-22 12:49:42 +01:00
parent 660447a314
commit ecc03183e0
3 changed files with 27 additions and 2 deletions

View File

@ -1,2 +1,5 @@
MAILTO = wolfgang.hottgenroth@icloud.com
CONTENT_TYPE = "text/html"
0 0 1 * * user /opt/app/monatliche-forderung-eintragen.py
* * * * * user /opt/app/monatliche-forderung-ueberwachen.py

View File

@ -2,6 +2,7 @@
import requests
import datetime
from Cheetah.Template import Template
class ResourceNotFoundException(Exception): pass
@ -12,6 +13,7 @@ def getJson(url):
return resp.json()
TEMPLATE_FILE = "report.tmpl"
BASE_URL = "http://172.16.10.29:5000/hv"
URL_MIETERS_ACTIVE = "{base}/mieters/active"
URL_SALDO_BY_MIETER = "{base}/mieter/{mieterId}/saldo/{year}"
@ -22,12 +24,19 @@ CURRENT_YEAR = datetime.datetime.now().year
try:
activeMieters = getJson(URL_MIETERS_ACTIVE.format(base=BASE_URL))
mieters = [ { 'vorname': x['vorname'], 'nachname': x['nachname'], 'id': x['id'] } for x in activeMieters ]
mietersToReport = []
for mieter in mieters:
saldoByMieter = getJson(URL_SALDO_BY_MIETER.format(base=BASE_URL, mieterId=mieter['id'], year=CURRENT_YEAR))
if abs(saldoByMieter['saldo']) > 0.5:
name = "{vorname} {nachname}".format(**mieter)
print("{name:30s}: {saldo:10.2f}".format(saldo=saldoByMieter['saldo'], name=name))
mietersToReport.append({
'vorname': mieter['vorname'],
'nachname': mieter['nachname'],
'saldo': saldoByMieter['saldo']
})
params = { 'mietersToReport': mietersToReport }
report = Template(file=TEMPLATE_FILE, searchList=[ params ])
print(report)
except Exception as e:
print("ERROR: {}".format(e))

13
report.tmpl Normal file
View File

@ -0,0 +1,13 @@
<html>
<head></head>
<body>
<table>
#for $mieter in $mietersToReport
<tr>
<td>$mieter.vorname $mieter.nachname</td>
<td>$mieter.saldo €</td>
</tr>
#end for
</table>
</body>
</html>