test changes
This commit is contained in:
2
crontab
2
crontab
@ -1,2 +1,2 @@
|
||||
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
|
||||
|
@ -1,4 +1,33 @@
|
||||
#!/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))
|
||||
|
Reference in New Issue
Block a user