Skip to content

Serina Grill DSPT2 #187

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

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
16 changes: 16 additions & 0 deletions sprint-challenge/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
flask = "*"
flask-sqlalchemy = "*"
requests = "*"
python-decouple = "*"
python-dateutil = "*"

[requires]
python_version = "3.7"
162 changes: 162 additions & 0 deletions sprint-challenge/Pipfile.lock

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions sprint-challenge/app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from flask import Flask

app = Flask(__name__)

from app import aq_dashboard


app.run(debug=True)
70 changes: 70 additions & 0 deletions sprint-challenge/app/aq_dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""OpenAQ Air Quality Dashboard with Flask."""
# imports
import openaq
from app import app
from flask import Flask, jsonify
from flask_sqlalchemy import SQLAlchemy
from decouple import config
import requests

# app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite3'

DB = SQLAlchemy(app)
api = openaq.OpenAQ()


def utc_values(city='Los Angeles', parameter='pm25'):
"""Takes in air quality measurements and returns list of utc and values"""
status, body = api.measurements(city='Los Angeles', parameter='pm25')
big_dict = body['results']
date = []
for i in big_dict:
for x, y in i.items():
if x == 'date':
date.append(y)
utc = []
for b in date:
for c, d in b.items():
if c == 'utc':
utc.append(d)

value = []
for p in big_dict:
for q, r in p.items():
if q == 'value':
value.append(r)

list_of_zipped_items = list(zip(utc, value))
return list_of_zipped_items


@app.route('/')
def root():
"""Returns values greater than 10"""
risky = Record.query.filter(Record.value >= 10).all()
return str(risky)


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 '< Date-time: {} - Value: {} >'.format(self.datetime,
self.value)


@app.route('/refresh')
def refresh():
"""Pull fresh data from Open AQ and replace existing data."""
DB.drop_all()
DB.create_all()
la = utc_values(city='Los Angeles', parameter='pm25')
for v in la:
tupl = Record(datetime=v[0], value=v[1])
DB.session.add(tupl)

DB.session.commit()
return 'Data refreshed!'
Loading