Project 1 creates Music discovery app that uses Spotify API to dynamically fetch data form Spotify libraries to show top tracks of an Artist. The user will have option to pick an artist through a search bar on page. In case an artist is not picked the page will load top tracks for one of the three pre-selected artists.
Platform
This project is primarily made on amazons’ AWS cloud9 service. Cloud9 is a cloud-based IDE that lets us write, run, and debug out code just with a browser. And because it is a cloud-based service it makes it easy for us share our work.
Frame work
For Project 1 we are using Flask framework. Flask is a web framework, that provide us with tools, libraries and technologies that allow us to build and setup a web application.
Libraries
from flask import Flask, render_template, request, redirect
- Render_template: Flask configures jinj2 template automatically using grander_templete() method.
- request: request is used to make HTTP GET and POST requests
- redirect: redirect() is used to redirect a user to different endpoint.
from dotenv import load_dotenv, find_dotenv
Dotenv library is going to be used for calling environment variables stored in .env
file
load_dotenv
is use to load environment variable.find_dotenv()
can be used to find.env
file
import requests
Requests allows us to easily send HTTP requests.
Example:
requests.post(tocken_url, data=tocken_data, headers=tocken_header)
import base64
Base64 is used for RFC 3548 encoding, for URLs and HTTP POST requests. Example:
base64.b64encode(creds.encode())
from urllib.parse import urlencode
urllib.parse.urlencode() is used for generating the query string of a URL or data for a POST request
APIs
1. Token
- This API is used to get an access token using client id and client secret.
- Get spotify catalog information about an artist's top tracks using artist id and country.
- Get Spotify catalog information for a single artist identified by their unique Spotify ID.
4. Search API
- Get Spotify Catalog information about albums, artists, playlists, tracks, shows or episodes that match a keyword string.
5. Genius API
- Get song lyrics by passing in the song name
To use and run this project there are a couple of requirements:
1. Install Flask
To install flask open up the command prompt or terminal and type,
$ pip install Flask
in case that does not work type,
$ sudo pip install Flask
2. Install requests
To install Requests, simply run the following command in your terminal of choise:
$ python -m pip install requests
3. Install dotenv
To install dotenv run following command in terminal:
pip install python-dotenv
4. setup dotenv
- Create a
.env
file in the project directory containing Spotify Client id and Client secret in following format:
export sptfy_id = "your client id"
export sptfy_sectret = "your client secret"
export genius_token = "your genius api access token"
- Open up terminal and run command
python spotify_app.py
- Click on "Preview" >> "Preview running application"
(Disclaimer: If you are using Grammarly extension in your browser, the app may not work properly. Please open the page in incognito tab or disable Grammarly for the website.)