diff options
-rw-r--r-- | poller/__init__.py | 1 | ||||
-rw-r--r-- | poller/models.py | 19 | ||||
-rw-r--r-- | poller/routes.py | 7 |
3 files changed, 27 insertions, 0 deletions
diff --git a/poller/__init__.py b/poller/__init__.py index c0c25c0..1e1580b 100644 --- a/poller/__init__.py +++ b/poller/__init__.py @@ -30,5 +30,6 @@ APP.logger.info('SQLAlchemy pointed at ' + repr(db.engine.url)) #pylint: disable=wrong-import-position from . import models from . import commands +from . import routes db.create_all() diff --git a/poller/models.py b/poller/models.py index a5dd2fa..15b223d 100644 --- a/poller/models.py +++ b/poller/models.py @@ -32,3 +32,22 @@ class Day(db.Model): Helper to get all values from the database """ return cls.query.all() + + def serialize(self): + """ + used for json serialization + """ + return { + 'last_updated': self.last_updated, + 'alert_level': self.alert_level, + 'beds_available': self.beds_available, + 'isolation_off_campus': self.isolation_off_campus, + 'isolation_on_campus': self.isolation_on_campus, + 'new_staff': self.new_staff, + 'new_students': self.new_students, + 'quarantine_off_campus': self.quarantine_off_campus, + 'quarantine_on_campus': self.quarantine_on_campus, + 'tests_administered': self.tests_administered, + 'total_staff': self.total_staff, + 'total_students': self.total_students, + } diff --git a/poller/routes.py b/poller/routes.py new file mode 100644 index 0000000..4c0010b --- /dev/null +++ b/poller/routes.py @@ -0,0 +1,7 @@ +from flask import Flask, jsonify +from . import APP +from .models import Day + +@APP.route('/api/v0/history') +def _get_api_v0_history(): + return jsonify([day.serialize() for day in Day.get_all()]) |