From 7ac700ca91b64430d1ce87700808d1ec07df2e4a Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Thu, 25 Feb 2021 16:15:05 -0500 Subject: update gitignore --- .gitignore | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to '.gitignore') diff --git a/.gitignore b/.gitignore index acab611..48d472c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,23 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/python,vscode,linux +# Edit at https://www.toptal.com/developers/gitignore?templates=python,vscode,linux + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Python ### # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -50,6 +70,7 @@ coverage.xml *.py,cover .hypothesis/ .pytest_cache/ +pytestdebug.log # Translations *.mo @@ -70,6 +91,7 @@ instance/ # Sphinx documentation docs/_build/ +doc/_build/ # PyBuilder target/ @@ -109,6 +131,7 @@ venv/ ENV/ env.bak/ venv.bak/ +pythonenv* # Spyder project settings .spyderproject @@ -128,8 +151,20 @@ dmypy.json # Pyre type checker .pyre/ -# Don't commit secrets! -config.py +# pytype static type analyzer +.pytype/ + +# profiling data +.prof -# don't commit data -data/ +### vscode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# End of https://www.toptal.com/developers/gitignore/api/python,vscode,linux + +config.py -- 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 '.gitignore') 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