Skip to content

Commit 9a75db0

Browse files
committed
restrict timespan api to 7 day ranges
1 parent 6eb4a8d commit 9a75db0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

park_api/app.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime
1+
from datetime import datetime, timedelta
22
from os import getloadavg
33

44
from flask import Flask, jsonify, abort, request
@@ -135,8 +135,10 @@ def get_longtime_forecast(city, lot_id):
135135
return ("Error 400: invalid API version", 400)
136136

137137
try:
138-
datetime.strptime(date_from, '%Y-%m-%dT%H:%M:%S')
139-
datetime.strptime(date_to, '%Y-%m-%dT%H:%M:%S')
138+
delta = datetime.strptime(date_to, '%Y-%m-%dT%H:%M:%S') - datetime.strptime(date_from, '%Y-%m-%dT%H:%M:%S')
139+
if delta > timedelta(days=7):
140+
return ("Error 400: Time ranges cannot be greater than 7 days. "
141+
"To retrieve more data check out the <a href=\"https://parkendd.de/dumps\">dumps</a>.", 400)
140142
except ValueError:
141143
return ("Error 400: from and/or to URL params "
142144
"are not in ISO format, e.g. 2015-06-26T18:00:00", 400)

0 commit comments

Comments
 (0)