The source code of a web app for recording weather observations. Made as a pre-assignment for Reaktor Summer 2018 recruitment (assignment here (in Finnish).)
For the back end I used Flask, as I've used it for a few projects and really liked and wanted to get to know it better. Also, it seemed like the perfect choice for a project where quick prototyping is key. It uses MySQL for saving the observations, using Flask-SQLAlchemy as an ORM.
The front end is built using React. Mostly because I've been studying it recently and wanted to continue using it, and also because it fits the needs of the project well.
The app uses WebSockets for real time updates (ie. when some else records an observation).
Currently, the app doesn't validate user generated data that well by itself. You can't record observations where the temperatures go greatly beyond current world records. For data validation, the app trusts its users: For every location, there is a 'detailed view' where you can inspect last weeks observations, and flag suspicious ones. Once an observation has been flagged 5 or more times, it will not be shown in the future (it will remain in the database, as the flaggings may be unjustified or it may still be valid for 'research').
The app uses a file called config.py
in the root of the project. Here's a sample of what is needed:
# The top secret login details to the database.
db_config = {
'user': 'REDACTED',
'pw': 'REDACTED',
'db': 'REDACTED',
'host': 'REDACTED',
'port': 'REDACTED'
}
secret_key = 'REDACTED'
To use the get_weather.py
-utility, you need to have an API key to OpenWeatherMap saved in util/weather_api.py
.
api_key = 'REDACTED'
The directory util/
contains a few useful utilities for development. db_initializer.py
creates the database (config.py
must be set up for this to work). get_weather.py
is a script that runs continuously, getting the current weather hourly from OpenWeatherMap and sending it to the server using its API. This way the app always has some recent-ish data to work with, and it will show up on the logs the same way as 'real' observations.
The app logs all sent observations in a file in its root directory in addition to the database.