From 2db9fcf921c5302336dfd3bc72983692b345d2aa Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Thu, 25 Feb 2021 20:54:00 -0500 Subject: reqs stuff and remove swagger html --- config.env.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'config.env.py') diff --git a/config.env.py b/config.env.py index fd7c9ac..6726cb3 100644 --- a/config.env.py +++ b/config.env.py @@ -12,6 +12,4 @@ import os # Defaults for flask configuration IP = os.environ.get('IP', '127.0.0.1') PORT = os.environ.get('PORT', 5000) -#SERVER_NAME = os.environ.get('SERVER_NAME', 'localhost:5000') SECRET_KEY = os.environ.get('SESSION_KEY', default=''.join(secrets.token_hex(16))) - -- cgit v1.2.3 From 72b07e05e50c2c93d6f195a3ebe15544c4afe171 Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Thu, 25 Feb 2021 21:15:24 -0500 Subject: Update config file --- config.env.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'config.env.py') diff --git a/config.env.py b/config.env.py index 6726cb3..8334eeb 100644 --- a/config.env.py +++ b/config.env.py @@ -1,15 +1,18 @@ -import secrets -import os +""" +Default configuration settings and environment variable based configuration logic + See the readme for more information +""" -# Values in this file are loaded into the flask app instance, `demo.APP` in this -# demo. This file sources values from the environment if they exist, otherwise a -# set of defaults are used. This is useful for keeping secrets secret, as well -# as facilitating configuration in a container. Defaults may be overriden either -# by defining the environment variables, or by creating a `config.py` file that -# contains locally set secrets or config values. +from os import environ +import secrets +# Flask config +DEBUG = False +IP = environ.get('POLLER_IP', 'localhost') +PORT = environ.get('POLLER_PORT', '8000') +PROTOCOL = environ.get('POLLER_PROTOCOL', 'http://') +SECRET_KEY = environ.get('POLLER_SECRET_KEY', default=''.join(secrets.token_hex(16))) -# Defaults for flask configuration -IP = os.environ.get('IP', '127.0.0.1') -PORT = os.environ.get('PORT', 5000) -SECRET_KEY = os.environ.get('SESSION_KEY', default=''.join(secrets.token_hex(16))) +# SQLAlchemy config +SQLALCHEMY_DATABASE_URI = environ.get('POLLER_DATABASE_URI', 'sqlite:////tmp/rit-covid-poller.db') +SQLALCHEMY_TRACK_MODIFICATIONS = False -- cgit v1.2.3 From 07ef35d0892ce652b2421ef2d101c743593ccf46 Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Thu, 25 Feb 2021 22:00:18 -0500 Subject: Clean up config and wsgi --- config.env.py | 5 +++-- wsgi.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'config.env.py') diff --git a/config.env.py b/config.env.py index 8334eeb..5241003 100644 --- a/config.env.py +++ b/config.env.py @@ -9,9 +9,10 @@ import secrets # Flask config DEBUG = False IP = environ.get('POLLER_IP', 'localhost') -PORT = environ.get('POLLER_PORT', '8000') -PROTOCOL = environ.get('POLLER_PROTOCOL', 'http://') +PORT = environ.get('POLLER_PORT', '5000') SECRET_KEY = environ.get('POLLER_SECRET_KEY', default=''.join(secrets.token_hex(16))) +LOG_LEVEL = environ.get('PACKET_LOG_LEVEL', 'INFO') +VERSION = '0.1.0' # SQLAlchemy config SQLALCHEMY_DATABASE_URI = environ.get('POLLER_DATABASE_URI', 'sqlite:////tmp/rit-covid-poller.db') diff --git a/wsgi.py b/wsgi.py index 31fc3f5..cd51ea3 100644 --- a/wsgi.py +++ b/wsgi.py @@ -4,5 +4,5 @@ Primary entry point for the app from poller import APP -if __name__ == "__main__": - APP.run(host=APP.config["IP"], port=int(APP.config["PORT"])) +if __name__ == '__main__': + APP.run(host=APP.config['IP'], port=int(APP.config['PORT'])) -- cgit v1.2.3 From 51079aa249b509e9160dd675fed13b3bacda661c Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Thu, 25 Feb 2021 22:31:38 -0500 Subject: Add import history command --- .gitignore | 2 +- config.env.py | 2 +- poller/__init__.py | 3 +++ poller/commands.py | 36 ++++++++++++++++++++++++++++++++++++ requirements.txt | 2 ++ 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 poller/commands.py (limited to 'config.env.py') diff --git a/.gitignore b/.gitignore index 48d472c..e1dec52 100644 --- a/.gitignore +++ b/.gitignore @@ -166,5 +166,5 @@ dmypy.json *.code-workspace # End of https://www.toptal.com/developers/gitignore/api/python,vscode,linux - config.py +data.db diff --git a/config.env.py b/config.env.py index 5241003..a56a930 100644 --- a/config.env.py +++ b/config.env.py @@ -15,5 +15,5 @@ LOG_LEVEL = environ.get('PACKET_LOG_LEVEL', 'INFO') VERSION = '0.1.0' # SQLAlchemy config -SQLALCHEMY_DATABASE_URI = environ.get('POLLER_DATABASE_URI', 'sqlite:////tmp/rit-covid-poller.db') +SQLALCHEMY_DATABASE_URI = environ.get('POLLER_DATABASE_URI', f'sqlite:///data.db') SQLALCHEMY_TRACK_MODIFICATIONS = False diff --git a/poller/__init__.py b/poller/__init__.py index e6eda4d..c0c25c0 100644 --- a/poller/__init__.py +++ b/poller/__init__.py @@ -29,3 +29,6 @@ APP.logger.info('SQLAlchemy pointed at ' + repr(db.engine.url)) #pylint: disable=wrong-import-position from . import models +from . import commands + +db.create_all() diff --git a/poller/commands.py b/poller/commands.py new file mode 100644 index 0000000..fc45dc7 --- /dev/null +++ b/poller/commands.py @@ -0,0 +1,36 @@ +""" +CLI commands for data management +""" +import json +import click +from dateutil import parser + +from . import APP, db +from .models import Day + +@APP.cli.command('import-history') +@click.argument('history_file') +def import_history(history_file): + """ + Import history from JSON file + """ + data = '{}' + with open(history_file, 'r') as file: + data = file.read() + parsed = json.loads(data) + for item in parsed: + if not parser.parse(item['last_updated']) in [day.last_updated for day in Day.get_all()]: + db.session.add(Day( + last_updated=parser.parse(item['last_updated']), + alert_level=item['alert_level'], + beds_available=item['beds_available'], + isolation_off_campus=item['isolation_off_campus'], + isolation_on_campus=item['isolation_on_campus'], + new_staff=item['new_staff'], + new_students=item['new_students'], + quarantine_off_campus=item['quarantine_off_campus'], + quarantine_on_campus=item['quarantine_on_campus'], + tests_administered=item['tests_administered'], + total_staff=item['total_staff'], + total_students=item['total_students'])) + db.session.commit() diff --git a/requirements.txt b/requirements.txt index ea4aff3..16b231a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,9 @@ MarkupSafe==1.1.1 mccabe==0.6.1 pylint==2.6.0 pylint-quotes==0.2.1 +python-dateutil==2.8.1 requests==2.24.0 +six==1.15.0 soupsieve==2.2 SQLAlchemy==1.3.23 toml==0.10.2 -- cgit v1.2.3