Console application for getting up-to-date information about countries.
The application allows you to receive from open sources and save to the files information about countries and provide it to the user.
Clone the repository to your computer:
git clone https://github.com/mnv/python-course-country-directory.gitInstall the appropriate software:
- Docker Desktop.
- Git.
- PyCharm (optional).
-
To configure the application copy
.env.sampleinto.envfile:cp .env.sample .env
This file contains environment variables that will share their values across the application. The sample file (
.env.sample) contains a set of variables with default values. So it can be configured depending on the environment.To access the API, visit the appropriate resources and obtain an access token:
- APILayer – Geography API (https://apilayer.com/marketplace/geo-api)
- OpenWeather – Weather Free Plan (https://openweathermap.org/price#weather)
Set received access tokens as environment variable values (in
.envfile):API_KEY_APILAYER– for APILayer access tokenAPI_KEY_OPENWEATHER– for OpenWeather access token
-
Build the container using Docker Compose:
docker compose build
This command should be run from the root directory where
Dockerfileis located. You also need to build the docker container again in case if you have updatedrequirements.txt. -
To see the documentation for the console command run:
docker compose run app python main.py --help
-
To start the application run:
docker compose up cron
A background program will start that will collect information about countries from various sources and save it to files in the
mediadirectory. The data collection process runs once per minute. The frequency of data updates depends on the settings in the variables (in.envfile):CACHE_TTL_COUNTRY(country data up-to-date time in seconds)CACHE_TTL_CURRENCY_RATES(currency rates data up-to-date time in seconds)CACHE_TTL_WEATHER(weather data up-to-date time in seconds)
-
After collecting all the data, you can query the country information by executing the command:
docker compose run app
This command will use its default parameters.
You can also specify needed parameters:
docker compose run app python main.py --location London
The project contains a special Makefile that provides shortcuts for a set of commands:
-
Build the Docker container:
make build
-
Generate Sphinx documentation run:
make docs-html
-
Autoformat source code:
make format
-
Static analysis (linters):
make lint
-
Autotests:
make testThe test coverage report will be located at
src/htmlcov/index.html. So you can estimate the quality of automated test coverage. -
Run autoformat, linters and tests in one command:
make all
Run these commands from the source directory where Makefile is located.
The project integrated with the Sphinx documentation engine. It allows the creation of documentation from source code. So the source code should contain docstrings in reStructuredText format.
To create HTML documentation run this command from the source directory where Makefile is located:
make docs-htmlAfter generation documentation can be opened from a file docs/build/html/index.html.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.