aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2021-02-25 22:01:13 -0500
committerGalen Guyer <galen@galenguyer.com>2021-02-25 22:01:13 -0500
commit7a66f7bdf01e004f55cfdf0ff9ff5cda35f65c3b (patch)
tree13d0fe9aa2a8cf5a9be8c65e15cdbb569e1d3562
parent07ef35d0892ce652b2421ef2d101c743593ccf46 (diff)
Add startup and model
-rw-r--r--poller/__init__.py28
-rw-r--r--poller/models.py34
2 files changed, 62 insertions, 0 deletions
diff --git a/poller/__init__.py b/poller/__init__.py
new file mode 100644
index 0000000..67b7ef2
--- /dev/null
+++ b/poller/__init__.py
@@ -0,0 +1,28 @@
+"""
+Startup code
+"""
+
+import os
+import logging
+from flask import Flask
+from flask_sqlalchemy import SQLAlchemy
+
+APP = Flask(__name__)
+
+# Load default configuration and any environment variable overrides
+_root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+APP.config.from_pyfile(os.path.join(_root_dir, 'config.env.py'))
+
+# Load file based configuration overrides if present
+_pyfile_config = os.path.join(_root_dir, 'config.py')
+if os.path.exists(_pyfile_config):
+ APP.config.from_pyfile(_pyfile_config)
+
+# Logger configuration
+logging.getLogger().setLevel(APP.config['LOG_LEVEL'])
+#pylint: disable=no-member
+APP.logger.info('Launching rit-covid-poller v' + APP.config['VERSION'])
+
+db = SQLAlchemy(APP)
+APP.logger.info('SQLAlchemy pointed at ' + repr(db.engine.url))
+#pylint: enable=no-member
diff --git a/poller/models.py b/poller/models.py
new file mode 100644
index 0000000..a5dd2fa
--- /dev/null
+++ b/poller/models.py
@@ -0,0 +1,34 @@
+"""
+Defines models
+"""
+from datetime import datetime
+from sqlalchemy import Column, Integer, String, DateTime
+
+from . import db
+
+#pylint: disable=too-few-public-methods
+class Day(db.Model):
+ """
+ Model for each day's data
+ """
+ __tablename__ = 'days'
+ last_updated = Column(DateTime, default=datetime.now, onupdate=datetime.now, \
+ primary_key=True, nullable=False)
+ alert_level = Column(String(16), nullable=False)
+ beds_available = Column(Integer, nullable=False)
+ isolation_off_campus = Column(Integer, nullable=False)
+ isolation_on_campus = Column(Integer, nullable=False)
+ new_staff = Column(Integer, nullable=False)
+ new_students = Column(Integer, nullable=False)
+ quarantine_off_campus = Column(Integer, nullable=False)
+ quarantine_on_campus = Column(Integer, nullable=False)
+ tests_administered = Column(Integer, nullable=False)
+ total_staff = Column(Integer, nullable=False)
+ total_students = Column(Integer, nullable=False)
+
+ @classmethod
+ def get_all(cls):
+ """
+ Helper to get all values from the database
+ """
+ return cls.query.all()