Skip to content

Heroku app using Postgres to log conditions at nearby ski hills

Notifications You must be signed in to change notification settings

iknowjerome/ski-monitor

 
 

Repository files navigation

ski-monitor

This repo provides tools for interactive plotting of historic and forecast:

  • temperatures
  • windspeed
  • precipitation [rain or snow]
  • current snow depth

For a range of ski resorts (the default ones being the ones near me).

For a demo, see this webapp, which is deployed (for free) via Heroku (it's awesome).

If you'd like to set up something similar for yourself, see the deployment section below.

Tech

This app uses:

  • the Dash package from Plotly for plotting + serving the webapp
  • the DarkSky API for current and forecast weather
  • OnTheSnow + BeautifulSoup for scraping current snow conditions
  • Heroku for deployment, which also gives us:
    • a Postgres database to store data
    • a Scheduler to update our database + scraped data once an hour
    • gunicorn for more robust serving than Flask provides

Setup

Requirements

Create a virtual environment with whatever framework takes your fancy (e.g. Conda or Virtualenv).

Now install the requirements:

pip install -r requirements.txt

You'll also need to visit DarkSky and get your API key. Once you've done that, run

export DARKSKY_KEY=<your DarkSky API key>

To check everything is tickety-boo, run the tests:

pytest tests.py

To run the web-app locally

To use the app, you'll need to create a Postgres database somewhere. I'd strongly recommend Heroku.

Once you've got a Postgres database setup, you'll need to export the DATABASE_URL for your database.

This is automaticaly set in Heroku and you can find it in the settings for your app.

export DATABASE_URL=<your database URL>

Now you're ready to run your app:

python app.py

This should return a URL which you can refer to for lovely JS graphs.

Deployment to Heroku

If you've never used Heroku before, check out their Getting Started guide.

However, this repo is provisioned to work out-of-the-box, so you only really need to:

  • Create a new project in Heroku

  • Use the Postgres DB add-on to create a new database

  • Use the Heroku Scheduler add-on to schedule the database updates every hour, with:

    python db_utils.py

  • Deploy the contents of this Git Repo to Heroku, by selecting the 'Deploy with Git' option under your project's deployment settings

Contents

app.py: the web app itself, defining which graphs are plotted

constants.py: definitions of the GPS co-ordinates and OnTheSnow URL's for each ski resport

darksky.py: tools for calling the darksky API and returning pandas dataframe

db_utils.py: tools for interacting with the Postgres database. When called from the command line (i.e. python db_utils.py), this updates the database with calls to the Darksky API.

plotting.py: tools for plotting wih Dash/Plotly

scraping.py: tools for scraping snow conditions from OnTheSnow

tests.py: minimal tests

Procfile: Procfile instructing Heroku how to run the app (using gunicorn)

About

Heroku app using Postgres to log conditions at nearby ski hills

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Jupyter Notebook 93.3%
  • Python 6.7%