This API is used to get worldwide timezones from a list of selected cities, by connecting to the http://worldtimeapi.org API.
In terminal, in the root folder of the app, install all the libraries listed in the Requirements.txt file:
pip install -r requirements.txtinstall
pip install virtualenv [--user]
###Creating a Virtual Enviroment create an environment in the root path of the project
python3 -m venv [/path/to/new/virtual/environment]
Activate the new virtual environment
source [venv path]/bin/activate
Then Run the app:
python main.pyIn the browser, go to:
localhost:4240/timesit will output a JSON response like this:
{
"Africa/Accra": "2022-07-29T12:36:29.855235+00:00",
"America/Belize": "2022-07-29T12:36:29.916750+00:00",
"Antarctica/Davis": "2022-07-29T12:36:29.991832+00:00",
"Asia/Baghdad": "2022-07-29T12:36:30.064340+00:00",
"Australia/Eucla": "2022-07-29T12:36:30.137697+00:00",
"Europe/Zurich": "2022-07-29T12:36:30.268828+00:00"
}To get just one city, go to:
localhost:4240/times/city/[Continent Name]/[City Name]]
For example:
localhost:4240/times/city/America/Belize
it will output a JSON response like this:
{
"America/Belize": "2022-07-29T12:36:29.916750+00:00",
}The Redis server needs to be installed and run. Without the Redis service this microservice won't run.
Mac OS
https://redis.io/docs/getting-started/installation/install-redis-on-mac-os/
Windows
https://redis.io/docs/getting-started/installation/install-redis-on-windows/
Just execute the Docker Compose command:
docker-compose up -d
It will create three containers:
Then you can just go to:
http://localhost/4242/times
To retrieve the multiple timezones.
#Testing
Run the file testTimes
python testTimes.py
It will run two tests, one to check the Redis connection and another to check whether a request to the World Time API can be established.