diff options
author | Galen Guyer <galen@galenguyer.com> | 2020-11-13 20:09:34 -0500 |
---|---|---|
committer | Galen Guyer <galen@galenguyer.com> | 2020-11-13 20:09:34 -0500 |
commit | 8d1cae7914b6b50d849d9a3253dd0ce8f8182620 (patch) | |
tree | eed8e207f18a8470e5e18dc0c8d52f6e2240d464 /poller | |
parent | 4d70954385037f4d896d3773ee33bc15560ad255 (diff) |
clean up diff route
Diffstat (limited to 'poller')
-rw-r--r-- | poller/__init__.py | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/poller/__init__.py b/poller/__init__.py index c6d0b0e..daa4fa8 100644 --- a/poller/__init__.py +++ b/poller/__init__.py @@ -263,27 +263,23 @@ def _api_v0_difference(): @APP.route('/api/v0/diff') def _api_v0_diff(): - query = request.args.get('q') - if query is None: - return make_repsonse(jsonify({'error': 'you must specify either a number or a range'}), 400) - first = -1 - last = -1 - if ',' not in query: + first = request.args.get('first') + last = request.args.get('last') + data = get_all_from_db() + if first is None: + first = 0 + else: try: - first = int(query) - except: - return make_repsonse(jsonify({'error': 'you must specify either a number or a range'}), 400) + first = int(first) + except: + first = 0 + if last is None: + last = len(data) - 1 else: try: - first = int(query.partition(',')[0]) - last = int(query.partition(',')[2]) + last = int(last) except: - return make_repsonse(jsonify({'error': 'you must specify either a number or a range'}), 400) - data = get_all_from_db() - if first < 0 or (last is not -1 and last < first): - return make_response(jsonify({'error': 'both numbers must be > 0 and last > first'}), 400) - if last >= len(data): - return make_response(jsonify({'error': f'last must be less than or equal to {len(data) - 1}'}), 400) + last = len(data) - 1 latest = data[last] prev = data[first] data = { @@ -298,6 +294,7 @@ def _api_v0_diff(): 'isolation_off_campus': latest["isolation_off_campus"] - prev["isolation_off_campus"], 'beds_available': latest["beds_available"] - prev["beds_available"], 'tests_administered': latest["tests_administered"] - prev["tests_administered"], + 'description': f'day {first} to {last}' } return jsonify(data) |