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')
|
start = data.get('start')
|
||||||
end = data.get('end')
|
end = data.get('end')
|
||||||
is_werktage = data.get('werktage', False)
|
is_werktage = data.get('werktage', False)
|
||||||
|
bundesland = data.get('bundesland')
|
||||||
try:
|
try:
|
||||||
d1 = datetime.strptime(start, '%Y-%m-%d')
|
d1 = datetime.strptime(start, '%Y-%m-%d')
|
||||||
d2 = datetime.strptime(end, '%Y-%m-%d')
|
d2 = datetime.strptime(end, '%Y-%m-%d')
|
||||||
if is_werktage:
|
if is_werktage:
|
||||||
if d1 > d2:
|
if d1 > d2:
|
||||||
d1, d2 = d2, d1
|
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:
|
else:
|
||||||
tage = abs((d2 - d1).days)
|
tage = abs((d2 - d1).days)
|
||||||
return jsonify({'result': tage})
|
return jsonify({'result': tage})
|
||||||
|
@@ -21,7 +21,12 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"start": { "type": "string", "format": "date" },
|
"start": { "type": "string", "format": "date" },
|
||||||
"end": { "type": "string", "format": "date" },
|
"end": { "type": "string", "format": "date" },
|
||||||
"werktage": { "type": "boolean", "default": false }
|
"werktage": { "type": "boolean", "default": false },
|
||||||
|
"bundesland": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Bundesland-Kürzel für Feiertagsberücksichtigung (nur bei werktage=true)",
|
||||||
|
"enum": ["BW", "BY", "BE", "BB", "HB", "HH", "HE", "MV", "NI", "NW", "RP", "SL", "SN", "ST", "SH", "TH"]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"required": ["start", "end"]
|
"required": ["start", "end"]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user