Skip to content

sebaxtian/weather-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

weather-api

This is an example of Weather API, the weather data is collected from Open Weather Map You should be create an account and generate a new API key to use in this project.


Work in progress ...

Roadmap

  • Add Project Description
  • Add About the Project
  • Requirements
  • Create and Setup Virtual Environment
  • Install Requeriments
  • Setup Environment Variables
  • Run Migrations
  • Python Unit Testing
  • Run the Project Locally
  • Create Admin User
  • Login Django Admin Site
  • Postman API Documentation
  • Run Automated Testing with Postman
  • Getting Started Video

About the Project

This project is a bit demo to implement a Django API REST, it requests weather data from Open Weather Map service, it's calling Weather API and expose a GET endpoint to request the current weather as a human human-readable format, this project has unit testing with pytest, cache data with timeout 2 minutes by default, some attributes can be set up via environment variables using the .env file.

The repository on GitHub has an Action to run a CI process for each push/push_request to develop branch, when that happens all tests are executed by pytest, all tests need to be approved, thus the develop branch is merged into the master branch. Finally, the Heroku service deploys the master branch and runs the application, you can use the Postman API Documentation to use the Weather API endpoint.

This project is in progress and could be refactorized to better performance you can check some TODO's on the code.

Requirements

In order to run the project locally, you will need the following requeriments:

  • Linux Debian/Ubuntu, Ubuntu 18.04.5 LTS^
  • Python 3.8^
  • curl 7.58.0^
  • libpq-dev
  • Heroku CLI

Create and Setup Virtual Environment

Run the instructions below in a terminal to create and setup the Python virtual environment:

# Linux terminal
python -m venv .venv
source .venv/bin/activate

Install Requeriments

  • PostgreSQL library
# Linux terminal
sudo apt install libpq-dev
  • Heroku CLI
# Linux terminal
curl https://cli-assets.heroku.com/install.sh | sh
  • Python project requirements
# Linux terminal
pip install -r requirements.txt

Setup Environment Variables

# Linux terminal
cp -fv example.env .env

After copy the example.env file to .env you can edit and change the values in the .env file, by default you can use the same file.

Run Migrations

# Within api/ folder run in a terminal
python manage.py makemigrations
python manage.py migrate

Python Unit Testing

# Within api/ folder run in a terminal
pytest

Run the Project Locally

Now the project is available to run locally, running a terminal:

# Run the app locally
heroku local web

Then open http://localhost:5000/admin in your browser.

Please, to deploy application on Heroku you should be DISABLE_COLLECTSTATIC:

# Disabling Collectstatic
heroku config:set DISABLE_COLLECTSTATIC=1

Create Admin User

Django Admin Site needs an Admin User, read the documentation here

# Within api/ folder run in a terminal
python manage.py createsuperuser
# ---
Username: sebaxtian
Email address: sebaxtian@example.com
Password: **********
Password (again): *********
Superuser created successfully.

Remember this admin user will be used by the Django Admin Site.

Login Django Admin Site

Open the browser and go to:

http://localhost:5000/admin

Use the Admin username and password to Login into the Django Admin Site.

Login Admin Site

Postman API Documentation

Read and review the Weather API Documentation in Postman:

Weather API Documentation

Run Automated Testing with Postman

Run Automated Testing with Postman Here

Getting Started Video

Getting Started Video Here

About

This is an example of Weather API, the weather data is collected from Open Weather Map

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors