-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.py
33 lines (24 loc) · 1.07 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sys
import requests
import json
if len(sys.argv) != 2:
sys.exit()
response = requests.get("https://itunes.apple.com/search?entity=song&limit=1&term=" + sys.argv[1])
print(response.json())
#make a proper format for the api data we received
import sys
import requests
import json
if len(sys.argv)!=2:
sys.exit()
response = requests.get("https://itunes.apple.com/search?entity=song&limit=2&term=" + sys.argv[1])
print(response.json())
#just printing as we have them in the API key and understand it is difficult to understand the data
print("-----------------------------------------------------------------------------------------------")
print(json.dumps(response.json(), indent=2))
#using dumps creating a 2 spaces in the file representing
print("----------------------------------------------------------------------------------------------------")
#if we need any specific things from the API like songs or something use below for loop and proper allignment in the file
o = response.json()
for result in o["results"]:
print(result["trackName"], result["trackPrice"])