Reputation: 1
I am a new learner to Python and am being asked to write a program that asks the user for a search term and then perform a search using the iTunes search service for the entity type album. The program should then print how many search results where returned. For each result print the artist name, the album name and track count. I am supposed to use the get() function and the json() method.
Can someone please start me on the right path? I feel lost with this program.
Upvotes: 0
Views: 970
Reputation: 350
Install the package iGetMusic by:
pip install iGetMusic
This allows you to search songs via:
import iGetMusic
song = iGetMusic.get(term="SEARCH TERM")
#And get the author via:
song[x].getArtistName()
For more infos to iGetMusic visit:
iGetMusic Github
Upvotes: 2
Reputation: 1
import requests as r
Count = 0
artist = ""
album = ""
trackcount = 0
x = input("Please enter a search term: ")
url = f"https://itunes.apple.com/search?term={x}&entity=album"
f = r.get(url)
d = f.json()
for x in d:
if x == "resultCount":
count = d["resultCount"]
print(f"The search returned {str(count)} results.")
elif x == "results":
for lx in d["results"]:
artist = lx["artistName"]
album = lx["collectionName"]
trackcount = lx["trackCount"]
print(f"Artist: {artist} - Album: {album} - Track Count: {str(trackcount)}")
Upvotes: 0
Reputation: 1
Linda, I think we're in the same OpenSAP class... this should get you going.
import json
import requests as r
x = input("Please enter a search term: ")
url = f'https://itunes.apple.com/search?term={x}&entity=album'
r = r.get(url)
print(f"The search returned {r.text.count(x)} results."
Upvotes: 0