From 6746140ea31c9f3a2d1b098f8c9cbb70cb3b86b7 Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Thu, 25 Feb 2021 16:35:17 -0500 Subject: Update requirements and add flask-sqlalchemy --- requirements.txt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'requirements.txt') diff --git a/requirements.txt b/requirements.txt index 8b69505..7e8c448 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,8 @@ +click==7.1.2 Flask==1.1.2 -gunicorn==20.0.4 -pylint==2.6.0 -pylint-quotes==0.2.1 -requests==2.24.0 -beautifulsoup4==4.9.3 \ No newline at end of file +Flask-SQLAlchemy==2.4.4 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==1.1.1 +SQLAlchemy==1.3.23 +Werkzeug==1.0.1 -- cgit v1.2.3 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 - requirements.txt | 16 + swagger.html | 3057 ------------------------------------------------------ 3 files changed, 16 insertions(+), 3059 deletions(-) delete mode 100644 swagger.html (limited to 'requirements.txt') 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))) - diff --git a/requirements.txt b/requirements.txt index 7e8c448..ea4aff3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,24 @@ +astroid==2.5 +beautifulsoup4==4.9.3 +certifi==2020.12.5 +chardet==3.0.4 click==7.1.2 Flask==1.1.2 Flask-SQLAlchemy==2.4.4 +gunicorn==20.0.4 +idna==2.10 +isort==5.7.0 itsdangerous==1.1.0 Jinja2==2.11.3 +lazy-object-proxy==1.5.2 MarkupSafe==1.1.1 +mccabe==0.6.1 +pylint==2.6.0 +pylint-quotes==0.2.1 +requests==2.24.0 +soupsieve==2.2 SQLAlchemy==1.3.23 +toml==0.10.2 +urllib3==1.25.11 Werkzeug==1.0.1 +wrapt==1.12.1 diff --git a/swagger.html b/swagger.html deleted file mode 100644 index 575ae4a..0000000 --- a/swagger.html +++ /dev/null @@ -1,3057 +0,0 @@ - - - - - RIT COVID Poller - - - - - - - - - - - - - - - - - -
-
-
- -
-
-
-
-

RIT COVID Poller

-
-
-
- -
-
-

V0

-
-
-
-

getv0History

-

Gets all historical data

-
-
-
-

-

Returns data from every day where the dashboard changed

-

-
-
/v0/history
-

-

Usage and SDK Samples

-

- - -
-
-
curl -X GET "https://ritcoviddashboard.com/api/v0/history"
-
-
-
import io.swagger.client.*;
-import io.swagger.client.auth.*;
-import io.swagger.client.model.*;
-import io.swagger.client.api.V0Api;
-
-import java.io.File;
-import java.util.*;
-
-public class V0ApiExample {
-
-    public static void main(String[] args) {
-        
-        V0Api apiInstance = new V0Api();
-        try {
-            array[Day] result = apiInstance.getv0History();
-            System.out.println(result);
-        } catch (ApiException e) {
-            System.err.println("Exception when calling V0Api#getv0History");
-            e.printStackTrace();
-        }
-    }
-}
-
- -
-
import io.swagger.client.api.V0Api;
-
-public class V0ApiExample {
-
-    public static void main(String[] args) {
-        V0Api apiInstance = new V0Api();
-        try {
-            array[Day] result = apiInstance.getv0History();
-            System.out.println(result);
-        } catch (ApiException e) {
-            System.err.println("Exception when calling V0Api#getv0History");
-            e.printStackTrace();
-        }
-    }
-}
-
- -
-

-V0Api *apiInstance = [[V0Api alloc] init];
-
-// Gets all historical data
-[apiInstance getv0HistoryWithCompletionHandler: 
-              ^(array[Day] output, NSError* error) {
-                            if (output) {
-                                NSLog(@"%@", output);
-                            }
-                            if (error) {
-                                NSLog(@"Error: %@", error);
-                            }
-                        }];
-
-
- -
-
var RitCovidPoller = require('rit_covid_poller');
-
-var api = new RitCovidPoller.V0Api()
-
-var callback = function(error, data, response) {
-  if (error) {
-    console.error(error);
-  } else {
-    console.log('API called successfully. Returned data: ' + data);
-  }
-};
-api.getv0History(callback);
-
-
- - -
-
using System;
-using System.Diagnostics;
-using IO.Swagger.Api;
-using IO.Swagger.Client;
-using IO.Swagger.Model;
-
-namespace Example
-{
-    public class getv0HistoryExample
-    {
-        public void main()
-        {
-            
-            var apiInstance = new V0Api();
-
-            try
-            {
-                // Gets all historical data
-                array[Day] result = apiInstance.getv0History();
-                Debug.WriteLine(result);
-            }
-            catch (Exception e)
-            {
-                Debug.Print("Exception when calling V0Api.getv0History: " + e.Message );
-            }
-        }
-    }
-}
-
-
- -
-
<?php
-require_once(__DIR__ . '/vendor/autoload.php');
-
-$api_instance = new Swagger\Client\Api\V0Api();
-
-try {
-    $result = $api_instance->getv0History();
-    print_r($result);
-} catch (Exception $e) {
-    echo 'Exception when calling V0Api->getv0History: ', $e->getMessage(), PHP_EOL;
-}
-?>
-
- -
-
use Data::Dumper;
-use WWW::SwaggerClient::Configuration;
-use WWW::SwaggerClient::V0Api;
-
-my $api_instance = WWW::SwaggerClient::V0Api->new();
-
-eval { 
-    my $result = $api_instance->getv0History();
-    print Dumper($result);
-};
-if ($@) {
-    warn "Exception when calling V0Api->getv0History: $@\n";
-}
-
- -
-
from __future__ import print_statement
-import time
-import swagger_client
-from swagger_client.rest import ApiException
-from pprint import pprint
-
-# create an instance of the API class
-api_instance = swagger_client.V0Api()
-
-try: 
-    # Gets all historical data
-    api_response = api_instance.getv0_history()
-    pprint(api_response)
-except ApiException as e:
-    print("Exception when calling V0Api->getv0History: %s\n" % e)
-
-
- -

Parameters

- - - - - - -

Responses

-

Status: 200 - successful operation

- - - -
-
-
- -
- -
-
- -
-
-
-
-
-
-

getv0Latest

-

Gets the latest data

-
-
-
-

-

Returns the most recent data from the official dashboard

-

-
-
/v0/latest
-

-

Usage and SDK Samples

-

- - -
-
-
curl -X GET "https://ritcoviddashboard.com/api/v0/latest"
-
-
-
import io.swagger.client.*;
-import io.swagger.client.auth.*;
-import io.swagger.client.model.*;
-import io.swagger.client.api.V0Api;
-
-import java.io.File;
-import java.util.*;
-
-public class V0ApiExample {
-
-    public static void main(String[] args) {
-        
-        V0Api apiInstance = new V0Api();
-        try {
-            Day result = apiInstance.getv0Latest();
-            System.out.println(result);
-        } catch (ApiException e) {
-            System.err.println("Exception when calling V0Api#getv0Latest");
-            e.printStackTrace();
-        }
-    }
-}
-
- -
-
import io.swagger.client.api.V0Api;
-
-public class V0ApiExample {
-
-    public static void main(String[] args) {
-        V0Api apiInstance = new V0Api();
-        try {
-            Day result = apiInstance.getv0Latest();
-            System.out.println(result);
-        } catch (ApiException e) {
-            System.err.println("Exception when calling V0Api#getv0Latest");
-            e.printStackTrace();
-        }
-    }
-}
-
- -
-

-V0Api *apiInstance = [[V0Api alloc] init];
-
-// Gets the latest data
-[apiInstance getv0LatestWithCompletionHandler: 
-              ^(Day output, NSError* error) {
-                            if (output) {
-                                NSLog(@"%@", output);
-                            }
-                            if (error) {
-                                NSLog(@"Error: %@", error);
-                            }
-                        }];
-
-
- -
-
var RitCovidPoller = require('rit_covid_poller');
-
-var api = new RitCovidPoller.V0Api()
-
-var callback = function(error, data, response) {
-  if (error) {
-    console.error(error);
-  } else {
-    console.log('API called successfully. Returned data: ' + data);
-  }
-};
-api.getv0Latest(callback);
-
-
- - -
-
using System;
-using System.Diagnostics;
-using IO.Swagger.Api;
-using IO.Swagger.Client;
-using IO.Swagger.Model;
-
-namespace Example
-{
-    public class getv0LatestExample
-    {
-        public void main()
-        {
-            
-            var apiInstance = new V0Api();
-
-            try
-            {
-                // Gets the latest data
-                Day result = apiInstance.getv0Latest();
-                Debug.WriteLine(result);
-            }
-            catch (Exception e)
-            {
-                Debug.Print("Exception when calling V0Api.getv0Latest: " + e.Message );
-            }
-        }
-    }
-}
-
-
- -
-
<?php
-require_once(__DIR__ . '/vendor/autoload.php');
-
-$api_instance = new Swagger\Client\Api\V0Api();
-
-try {
-    $result = $api_instance->getv0Latest();
-    print_r($result);
-} catch (Exception $e) {
-    echo 'Exception when calling V0Api->getv0Latest: ', $e->getMessage(), PHP_EOL;
-}
-?>
-
- -
-
use Data::Dumper;
-use WWW::SwaggerClient::Configuration;
-use WWW::SwaggerClient::V0Api;
-
-my $api_instance = WWW::SwaggerClient::V0Api->new();
-
-eval { 
-    my $result = $api_instance->getv0Latest();
-    print Dumper($result);
-};
-if ($@) {
-    warn "Exception when calling V0Api->getv0Latest: $@\n";
-}
-
- -
-
from __future__ import print_statement
-import time
-import swagger_client
-from swagger_client.rest import ApiException
-from pprint import pprint
-
-# create an instance of the API class
-api_instance = swagger_client.V0Api()
-
-try: 
-    # Gets the latest data
-    api_response = api_instance.getv0_latest()
-    pprint(api_response)
-except ApiException as e:
-    print("Exception when calling V0Api->getv0Latest: %s\n" % e)
-
-
- -

Parameters

- - - - - - -

Responses

-

Status: 200 - successful operation

- - - -
-
-
- -
- -
-
- -
-
-
-
-
- -
-
-
- - - - - - - - - - - - - - -- 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 'requirements.txt') 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