API: Bundesland-Feiertage für REST API erweitert
- tage_werktage Endpunkt unterstützt jetzt bundesland Parameter - Swagger-Dokumentation aktualisiert mit bundesland Parameter - Alle 16 deutschen Bundesländer in der API-Dokumentation aufgelistet
This commit is contained in:
9
app.py
9
app.py
@@ -217,13 +217,20 @@ def api_tage_werktage():
|
||||
start = data.get('start')
|
||||
end = data.get('end')
|
||||
is_werktage = data.get('werktage', False)
|
||||
bundesland = data.get('bundesland')
|
||||
try:
|
||||
d1 = datetime.strptime(start, '%Y-%m-%d')
|
||||
d2 = datetime.strptime(end, '%Y-%m-%d')
|
||||
if is_werktage:
|
||||
if d1 > d2:
|
||||
d1, d2 = d2, d1
|
||||
tage = int(np.busday_count(d1.date(), (d2 + timedelta(days=1)).date()))
|
||||
holidays = []
|
||||
if bundesland:
|
||||
# Feiertage für alle Jahre im Bereich holen
|
||||
years = set([d1.year, d2.year])
|
||||
for y in years:
|
||||
holidays.extend(get_feiertage(y, bundesland))
|
||||
tage = int(np.busday_count(d1.date(), (d2 + timedelta(days=1)).date(), holidays=holidays))
|
||||
else:
|
||||
tage = abs((d2 - d1).days)
|
||||
return jsonify({'result': tage})
|
||||
|
Reference in New Issue
Block a user