Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Productization and Cloud Johan Mazorra Pull Request #170

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file added sc/.DS_Store
Binary file not shown.
15 changes: 15 additions & 0 deletions sc/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
flask = "*"
flask-sqlalchemy = "*"
requests = "*"
flask-migrate = "*"

[requires]
python_version = "3.7"
158 changes: 158 additions & 0 deletions sc/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions sc/aq_dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import openaq
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy

APP = Flask(__name__)
APP.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite3'
DB = SQLAlchemy(APP)


class Record(DB.Model):

id = DB.Column(DB.Integer, primary_key=True)


datetime = DB.Column(DB.String(25))
value = DB.Column(DB.Float, nullable=False)


def __repr__(self):
return '<Record date {}>'.format(self.datetime) \
+ '<value {}>'.format(self.value)


api = openaq.OpenAQ()
(status, body) = api.measurements(city='Los Angeles', parameter='pm25')

date_and_value = []

for result in body['results']:
value = result['value']
(keys, values) = zip(*result['date'].items())
(utc_datetime, _local) = values
date_and_value.append((str(utc_datetime), value))


@APP.route('/')
def root():
my_list = date_and_value

return render_template('base.html', title='Home', list=my_list)


@APP.route('/main')
def main():
risky = Record.query.filter(Record.value >= 10).all()

return render_template('base.html', title='Potentially risky days',
list=risky)


@APP.route('/refresh')
def refresh():
''''''

DB.drop_all()
DB.create_all()

(status, body) = api.measurements(city='Los Angeles', parameter='pm25')

for result in body['results']:
value = result['value']
(keys, values) = zip(*result['date'].items())
(utc_datetime, _local) = values
new_record = Record(datetime=str(utc_datetime), value=value)
DB.session.add(new_record)
DB.session.commit()
return 'Data refreshed!'
Loading