About the project | Technologies | How to install | How to execute it | Response | API TESTS |
This is a microservice able to accept RESTFUL requests receiving as parameter either city name or lat long coordinates and returns a playlist (only track names is fine) suggestion according to the current temperature.`.
Some functionalities present on this project:
* Route to return musics of a playlist according to weather city or latitude and longitude;
* Spotify Developer API consummer;
* Weather Map API consummer;
🟩 PROJECT STATUS: FINISHED
- Python
- FAST API
- API Consumer
- Pydantic
- Pytest
- Mutation Tests
- Clone the repo with the following command: https://github.com/renatamoon/isis_api.git
- Create your virtual environment: python -m venv venv
- Activate your virtual environment: . venv\Scripts\Activate.ps1
Obs: If for any reason occurs and error: on powershell execute the following command: Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
- Execute requirements with the command: pip install -r requirements.txt
- Create your virtual environment: python -m venv venv
- Activate your virtual environment: source venv/bin/activate
- Execute requirements with the command: pip install -r requirements.txt
Create a project root .env
file and change your local strings connections to do the properly connection
# AUTHORIZATION
CLIENT_ID=""
CLIENT_SECRET_KEY=""
SPOTIFY_TOKEN_URL="https://accounts.spotify.com/api/token"
# PLAYLISTS URLS
PARTY_PLAYLIST_URL="https://api.spotify.com/v1/playlists/37i9dQZF1DX7e8TjkFNKWH/tracks?market=BR&limit=7"
POP_PLAYLIST_URL="https://api.spotify.com/v1/playlists/74Zp7I7BsiFg4T7wFiV5Iu/tracks?market=BR&limit=7"
ROCK_PLAYLIST_URL="https://api.spotify.com/v1/playlists/6jmDxyne7FJ3fVA9CkGYpd/tracks?market=BR&limit=7"
CLASSIC_PLAYLIST_URL="https://api.spotify.com/v1/playlists/6dI1MmIBasFV59ritLTxIJ/tracks?market=BR&limit=7"
# OPEN WEATHER API
OPEN_WEATHER_API_KEY=""
COORDINATES_URL="https://api.openweathermap.org/data/2.5/onecall?lat=%s&lon=%s&appid=%s&units=metric"
CITY_WEATHER_URL="http://api.openweathermap.org/data/2.5/weather?"
- To Execute the application run the command:
uvicorn main:app --reload
or manually run themain.py
file.
- To user the FastAPI user the router:
http:{your-host}/get_playlist_weather/docs
- Use the router on your Postman/Insomnia/Swagger:
http:{your-host}/get_playlist_weather
;
- search tracks by city, pass the query param:
city
- search tracks by latitude and longitude, pass the query params:
latitude
&longitude
- Expected return of the route
/get_playlist_weather
when passingcity
query param:
{
"tracks_for_you": [
{
"music_id": "5HCyWlXZPP0y6Gqq8TgA20",
"artist_name": "Justin Bieber",
"music_name": "STAY (with Justin Bieber)",
"album_name": "STAY (with Justin Bieber)"
},
{
"music_id": "4Dvkj6JhhA12EX05fT7y2e",
"artist_name": "Harry Styles",
"music_name": "As It Was",
"album_name": "Harry's House"
},
{
"music_id": "7mFj0LlWtEJaEigguaWqYh",
"artist_name": "Dua Lipa",
"music_name": "Sweetest Pie",
"album_name": "Sweetest Pie"
},
{
"music_id": "3DarAbFujv6eYNliUTyqtz",
"artist_name": "Doja Cat",
"music_name": "Kiss Me More (feat. SZA)",
"album_name": "Planet Her"
}
],
"about_your_weather": {
"city_or_timezone": "Delhi",
"temperature": 29.05,
"description": "mist"
}
}
- Example of expected response of the route when an error happened:
{
"request_status": false,
"status": 2,
"msg": "Error fetching data from Weather API"
}
-
To get the coverage of the project tests run the command on root path:
pytest --cov-report term-missing --cov-config=.coveragerc --cov=src -v
-
To run the mutatest and get the mutants survivor tolerance, run the command on root path:
bash mutation_test.sh
-
Coverage:
- Mutation Survivor Tolerance: