diff options
author | Galen Guyer <galen@galenguyer.com> | 2020-10-31 13:07:11 -0400 |
---|---|---|
committer | Galen Guyer <galen@galenguyer.com> | 2020-10-31 13:07:11 -0400 |
commit | 349c81c8964bce1f910b4402639f8d99f737c044 (patch) | |
tree | 461ea9f6194765a3b30c8b7a0b247c609edab9ab /poller | |
parent | 8cd51216bc28cb41eee489372fbbf4362016ca92 (diff) |
add updatedb method
Diffstat (limited to 'poller')
-rw-r--r-- | poller/__init__.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/poller/__init__.py b/poller/__init__.py index 5c9caf2..4b6b7ab 100644 --- a/poller/__init__.py +++ b/poller/__init__.py @@ -44,6 +44,27 @@ def create_tables(): db_conn.commit() db_conn.close() +def update_db(): + with db_lock: + db_conn = sqlite3.connect('data/data.sqlite3') + c = db_conn.cursor() + sql = f'INSERT INTO `alertlevel` VALUES (datetime(\'now\'), \'{LATEST_DATA["alert_level"]}\');' + c.execute(sql) + sql = f'INSERT INTO `total` VALUES (datetime(\'now\'), {LATEST_DATA["total_students"]}, {LATEST_DATA["total_staff"]});' + c.execute(sql) + sql = f'INSERT INTO `new` VALUES (datetime(\'now\'), {LATEST_DATA["new_students"]}, {LATEST_DATA["new_staff"]});' + c.execute(sql) + sql = f'INSERT INTO `quarantine` VALUES (datetime(\'now\'), {LATEST_DATA["quarantine_on_campus"]}, {LATEST_DATA["quarantine_off_campus"]});' + c.execute(sql) + sql = f'INSERT INTO `isolation` VALUES (datetime(\'now\'), {LATEST_DATA["isolation_on_campus"]}, {LATEST_DATA["isolation_off_campus"]});' + c.execute(sql) + sql = f'INSERT INTO `beds` VALUES (datetime(\'now\'), {LATEST_DATA["beds_available"]});' + c.execute(sql) + sql = f'INSERT INTO `tests` VALUES (datetime(\'now\'), {LATEST_DATA["tests_administered"]});' + c.execute(sql) + db_conn.commit() + db_conn.close() + def data_is_same(current_data): global LATEST_DATA if LATEST_DATA is None or current_data is None: @@ -98,6 +119,8 @@ def get_data(): } if not data_is_same(current_data): LATEST_DATA = current_data + update_db() + return current_data get_data() |