This app uses weatherapi.com to fetch the weather data. There is a free tier with 1 Million Calls/month.
Before running the application, you need to set your API key as an environment variable. Here's how you can do it:
Open your .bashrc
or .bash_profile
file:
nano ~/.bashrc # or `nano ~/.bash_profile` if you're on macOS
Add the following line to the file:
export API_KEY=your_api_key
Replace your_api_key
with your actual API key.
Save and close the file.
Apply the changes:
source ~/.bashrc # or `source ~/.bash_profile` if you're on macOS
Now, every time you open a new terminal session, the API_KEY
environment variable will be set automatically.
To deploy the application on a Linux server with systemd, follow these steps:
Create a new service file in /etc/systemd/system/
with a .service
extension, for example, myapp.service
:
sudo nano /etc/systemd/system/myapp.service
Add the following content to the service file:
[Unit]
Description=Gunicorn instance to serve myapp
After=network.target
[Service]
User=yourusername
Group=www-data
WorkingDirectory=/path/to/your/app
Environment="PATH=/path/to/your/app/env/bin"
ExecStart=/path/to/your/app/env/bin/gunicorn -w 4 server:app
[Install]
WantedBy=multi-user.target
Replace yourusername
with your actual username, and /path/to/your/app
with the actual path to your Flask application.
Save and close the file.
Start the Gunicorn service you just created:
sudo systemctl start myapp
Enable the service to start on boot:
sudo systemctl enable myapp
Check the status of the service:
sudo systemctl status myapp
This will ensure that your Flask application starts on boot and restarts if it crashes.