Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
8 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
#Code by: Mazikeen El Bezra, ID: 10832578, documentation used: https://developer.musixmatch.com/documentation, https://requests.readthedocs.io/en/master/, adapted from: https://www.youtube.com/watch?v=WFRzKmpepj4&t=1108s | ||
''' function to return a specific number of the current top songs in a specific country''' | ||
def my_func(): | ||
import requests | ||
import requests #import request package which is used to import HTTP requests | ||
import json | ||
|
||
key= "&apikey=352a18cc5baa9cd34bd6fc0aa20c3401" | ||
url="https://api.musixmatch.com/ws/1.1/" | ||
|
||
print("Hello! Welcome to top songas charts!") | ||
print("Hello! Welcome to top songs chart!") | ||
amount = input("Please enter how many top songs would you like to view -->") | ||
country = input ("Please enter what country's charts would you like to view (i.e: us for america, uk for united kingdom, eg for egypt etc.-->") | ||
#creates a URL request using the user's inputs to call the API method | ||
charturl= url+ "chart.tracks.get"+ "?format=json&callback=callback" + "page=1&page_size=" + amount + "&country=" + country + key | ||
request = requests.get(charturl) | ||
data = request.json() | ||
request = requests.get(charturl) #sends a GET request to the specified url to get data from server | ||
data = request.json() #parse it as a JSON object | ||
#for loop used to access the 'track list' object and return two object values, the song name and artist name | ||
for i in data['message']['body']['track_list']: | ||
print("Song title: "+i['track']['track_name']+" ->Artist: "+i['track']['artist_name']) | ||
|