Weather-Zone is a weather forecast application utilising multiple third-party weather forecasters, to provide address-based weather forecasts.
The development environment requires:
Artifact | Download and installation instructions |
---|---|
Node.js | https://nodejs.org/en/download/ |
npm | Included with Node.js installation |
git | https://git-scm.com/downloads |
Python | https://www.python.org/downloads/ |
Poetry | https://python-poetry.org/docs/#installation |
Django | https://www.djangoproject.com/download/ |
In an appropriate folder, run the following commands:
> git clone https://github.com/ibuttimer/weather-zone.git
> cd weather-zone
Alternatively, most IDEs provide an option to create a project from Version Control.
It is recommended that a virtual environment be used for development purposes. There are numerous options available; e.g. poetry, venv, pyenv etc.
Please see Switching between environments.
In a terminal window, in the weather-zone
folder, run the following command to setup required environment artifacts:
> npm install
In the weather-zone
folder, run the following command to install the necessary python packages:
> poetry install
Key | Value |
---|---|
ENV_FILE | If using an environment file, specifies the file to use. Defaults to .env in the project root folder. |
PORT | Port application is served on; default 8000 |
DEBUG | A boolean that turns on/off debug mode; see Boolean environment variables |
SECRET_KEY | Secret key for a particular Django installation. See Secret Key Generation |
DATABASE_URL | Database url |
REMOTE_DATABASE_URL | Url of remote PostgreSQL database resource. Note: Only required for admin purposes, see database configuration under Cloud-based Deployment |
FONTAWESOME_URL | Fontawesome kit url. See Use a Kit |
REQUESTS_TIMEOUT | Requests timeout in seconds |
FORECAST_PROVIDERS | List of forecast providers to use, see FORECAST_PROVIDERS environment variable. |
LOCATIONFORECAST_<provider id> | Individual forecast provider configuration settings, see LOCATIONFORECAST_<provider id> environment variables. |
DEFAULT_SEND_EMAIL | Email address to send emails from. Only valid when development mode is enabled, in production mode emails are sent from EMAIL_HOST_USER |
EMAIL_HOST | SMTP server to send email. Only valid when production mode is enabled. |
EMAIL_USE_TLS | Use Transport Layer Security (TLS) flag; see Boolean environment variables, default true. Only valid when production mode is enabled. |
EMAIL_PORT | SMTP server port. Only valid when production mode is enabled. |
EMAIL_HOST_USER | Email user account to send email. Only valid when production mode is enabled. |
EMAIL_HOST_PASSWORD | Email user account password. Only valid when production mode is enabled. |
STORAGE_PROVIDER | Storage provider; set to s3 to use an Amazon Web Service S3 bucket for storage or default to use Django's default storage |
GOOGLE_API_KEY | Google Geocoding API key |
MAXMIND_GEOIP_ACCOUNT | MaxMind GeoIP2 Web Services Account ID |
MAXMIND_GEOIP_KEY | MaxMind GeoIP2 Web Services License key |
EXTERNAL_HOSTNAME | Hostname of application on hosting service. Note: To specify multiple hosts, use a comma-separated list with no spaces. Note: Set to localhost,127.0.0.1 in local development mode |
Amazon S3-specific | |
AWS_ACCESS_KEY_ID | The access key for your AWS account. |
AWS_SECRET_ACCESS_KEY | The secret key for your AWS account. |
AWS_STORAGE_BUCKET_NAME | AWS S3 bucket name. |
Development-specific configuration | |
CACHED_GEOCODE_RESULT | Cached Google Geocoding response to use; e.g. '[{"address_components": [{"long_name": "50", ... }]' |
CACHED_MET_EIREANN_RESULT | Path relative to project root of forecast response to use; e.g. 'dev/data/met_eireann/cached_resp.xml' |
Set environment variables evaluating a boolean value, should be set to any of true
, on
, ok
, y
, yes
or 1
to set true, otherwise the variable is evaluated as false.
The locationforecast
application may be configured with multiple providers which utilise the
Locationforecast weather forecast API developed by Met Norway.
The FORECAST_PROVIDERS
environment variable is a comma-separated list of providers to use, of the form <provider app name>_<provider id>
.
The convention is to name the provider class in the form <provider id>Provider
where <provider id>
is camel-cased, e.g. met_eireann
becomes MetEireannProvider
.
And the module name should be <provider id>.py
e.g. met_eireann.py
.
E.g. the following configures two providers; met_eireann
and met_norway_classic
, which will load the MetEireannProvider
and MetNorwayClassicProvider
classes respectively.
FORECAST_PROVIDERS=locationforecast_met_eireann,locationforecast_met_norway_classic
See Locationforecast for more details on the providers.
The configuration for each provider in the FORECAST_PROVIDERS environment variable must be provided by an environment variable of the following format:
-
Environment variable name
LOCATIONFORECAST_<provider id>; where
<provider id>
is the id of the provider, e.g.met_eireann
. -
Environment variable value
A semicolon-seperated list of key-value pairs as outlined in the following table.
Key | Description |
---|---|
name | Display name of provider |
url | Provider website url. |
data_url | API url. See Using unsafe characters in URLs |
latitude | Latitude query parameter name, e.g. latitude=lat |
longitude | Longitude query parameter name, e.g. longitude=long |
from | From date/time query parameter name |
to | To date/time query parameter name |
tz | A valid IANA timezone; e.g. tz=Europe/Dublin |
country | ISO 3166-1 alpha-2 country code for which provider provides forecasts; e.g. country=IE |
E.g. the following configure the met_eireann
provider;
LOCATIONFORECAST_MET_EIREANN="name=Met Éireann;url=http://metwdb-openaccess.ichec.ie/metno-wdb2ts/locationforecast;latitude=lat;longitude=long;from=from;to=to;tz=UTC;country=IE"
Note: Keys not required by a particular provider should be omitted.
See Met Éireann Timezone anomaly for more details on the
tz
setting.
Set environment variables corresponding to the keys in Table 1: Configuration settings.
A convenient method of generating a secret key is to run the following command and copy its output.
$ python -c "import secrets; print(secrets.token_urlsafe())"
Procedures differ depending on the email provider used. for example, in order to configure Gmail as the email provider, the following actions must be performed.
- Login to Gmail
- Goto the Google Account settings and select Security
- Under
How you sign in to Google
ensure 2-Step Verification is enabled - Search for
App passwords
and create a new app password - Copy the generated app password, and store securely
Before running the application for the first time following cloning from the repository and setting up a new database,
the following steps must be performed, from a terminal window, in the weather-zone
folder.
$ python manage.py migrate
Enter Username
, Password
and optionally Email address
.
$ python manage.py createsuperuser
From django-allauth Post-Installation
- Add a Site for your domain in the database
-
Login to
http://<domain>/admin/sites/site/
as the previously created superuser, e.g. http://127.0.0.1:8000/admin/sites/site/ -
Add a Site for your domain (django.contrib.sites app).
E.g.
Domain name Display name 127.0.0.1:8000 my domain Note: The id (primary key) of the site must be added to the application configuration. See
SITE_ID
in Table 1: Configuration settings.
-
In order to run the development server, run the following command from the weather-zone
folder:
$ python manage.py runserver
By default, the server runs on port 8000 on the IP address 127.0.0.1. See runserver for details on passing an IP address and port number explicitly.
The application structure is as follows:
├─ README.md - this file
├─ docs - documentation
├─ data - application data
├─ locale - translation files
├─ manage.py - application entry point
├─ weather_zone - main Django application
├─ addresses - address application
├─ base - base application
├─ broker - service broker application
├─ forecast - application generating forecast data from provider data
├─ locationforecast - Locationforecast provider application
├─ user - user application
├─ utils - utility functions
├─ weather_warning - weather warning application
├─ static - static files
└─ templates - application templates
The site was deployed on Render.
The following steps were followed to deploy the website:
-
Login to Render in a browser
-
From the dashboard select
New -> Web Service
-
Connect to the git repository
-
Set following
Name
, (e.g.weather-zone
)- Choose an appropriate region
- Select the git branch to deploy
- Select
Python 3
runtime, - Set the Build command to
./build.sh
- Set the Start command to
gunicorn weather-zone.wsgi:application
- Select
Create Web Service
-
To provision the application with a database, such as an ElephantSQL database.
- For an ElephantSQL database, follow the
Create a new instance
instructions under theGetting started
section of the ElephantSQL documentation.
- For an ElephantSQL database, follow the
-
Create an Amazon S3 bucket using Storing Django Static and Media Files on Amazon S3. See Configuring cross-origin resource sharing (CORS) and CORS configuration regarding setting the CORS configuration for the S3 bucket.
-
Under
Environment -> Environment Variables
add the following environment variablesKey Value PYTHON_VERSION Python version
Note: At time of writing the Render Python3 environment does not include the necessary Python headers to compile thepsycopg2
library for Python version 3.10.10, use Python version 3.9.16POETRY_VERSION Poetry version - Under
Environment -> Secret Files
add a file with the name.env
with the same environment variables as specified in Table 1: Configuration settings with the following differences:- The following variables are NOT required
- Development-specific configuration
- Add the following variables:
- DATABASE_URL
- Add Amazon S3-specific settings
- The following variables are NOT required
- Under
See Table 1: Configuration settings for details.
If any other settings vary from the defaults outlined in Table 1: Configuration settings they must be added as well.
-
Select the
Manual Deploy
to deploy the application. -
Initialise the database and Create a superuser
Involves the same procedure as outlined in Initialise the database and Create a superuser but may be run from the local machine.
-
From a Development and Local Deployment
-
Initialise the database
$ python manage.py migrate --database=remote
-
Create a superuser
Enter
Username
,Password
and optionallyEmail address
.$ python manage.py createsuperuser --database=remote
Note: Ensure to specify the
--database=remote
option to apply the change to the database specified by theREMOTE_DATABASE_URL
environment variable. -
-
-
Configure authentication
Follow the same procedure as outlined in Configure authentication using the Heroku domain as
<domain>
, e.g.weather-zone.onrender.com
The live website is available at https://weather-zone.onrender.com
The following resources were used to build the website.
-
Logo Weather forecast, Universal Multimedia License Agreement for Icons8, by Icons8.
Disclaimer: The extraction and reuse of icons8 graphics is prohibited, as stated in the license.
-
The favicon for the site was generated by RealFaviconGenerator from Weather forecast, Universal Multimedia License Agreement for Icons8, by Icons8
-
Weather forecast icons courtesy of The Norwegian Broadcasting Corporation
-
Wind direction icons derived from South icons created by Freepik - Flaticon
-
Warning icon, Universal Multimedia License Agreement for Icons8, by Icons8, background colour changed.
-
Boat icon, Universal Multimedia License Agreement for Icons8, by Icons8, background colour changed.
-
A icon, Universal Multimedia License Agreement for Icons8, by Icons8, background colour changed.
-
Breeze icon, Universal Multimedia License Agreement for Icons8, by Icons8, modified via Icons8 web tools.
-
Breeze icon, Universal Multimedia License Agreement for Icons8, by Icons8, modified via Icons8 web tools.
-
Wind icon, Universal Multimedia License Agreement for Icons8, by Icons8, modified via Icons8 web tools.
-
Storm icon, Universal Multimedia License Agreement for Icons8, by Icons8, modified via Icons8 web tools.
-
Tornado icon, Universal Multimedia License Agreement for Icons8, by Icons8, modified via Icons8 web tools.
-
Nothing Found icon, Universal Multimedia License Agreement for Icons8, by Icons8.
-
404 error icon created by Freepik - Flaticon
-
Explosion icon created by Freepik - Flaticon
-
Stop sign icon created by Freepik - Flaticon
-
Confusion icon created by Freepik - Flaticon
- Secret Key Generation courtesy of Humberto Rocha