test changes

This commit is contained in:
2021-02-22 12:03:13 +01:00
parent 46771fa5a2
commit 660447a314
2 changed files with 31 additions and 2 deletions

View File

@ -1,2 +1,2 @@
0 0 1 * * user /opt/app/monatliche-forderung-eintragen.py 0 0 1 * * user /opt/app/monatliche-forderung-eintragen.py
0 1 * * * user /opt/app/monatliche-forderung-ueberwachen.py * * * * * user /opt/app/monatliche-forderung-ueberwachen.py

View File

@ -1,4 +1,33 @@
#!/usr/bin/python3 #!/usr/bin/python3
print("Monatliche Forderung ueberwachen") import requests
import datetime
class ResourceNotFoundException(Exception): pass
def getJson(url):
resp = requests.get(url)
if resp.status_code != 200:
raise ResourceNotFoundException("URL: {}, Code: {}".format(url, resp.status_code))
return resp.json()
BASE_URL = "http://172.16.10.29:5000/hv"
URL_MIETERS_ACTIVE = "{base}/mieters/active"
URL_SALDO_BY_MIETER = "{base}/mieter/{mieterId}/saldo/{year}"
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 ]
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))
except Exception as e:
print("ERROR: {}".format(e))