-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitunes.py
More file actions
42 lines (27 loc) · 1.46 KB
/
Copy pathitunes.py
File metadata and controls
42 lines (27 loc) · 1.46 KB
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
32
33
34
35
36
37
38
39
40
41
42
# ## Calling for json files from url
# import requests
# import sys
# if len(sys.argv) != 2: # this forces used to include two arguments, name of file/song and then the name of artist
# sys.exit() # this will exit when used does not satisfy the argument above
# response = requests.get("https://itunes.apple.com/search?entity=song&limit=1&term=" + sys.argv[1]) # This is addressing the url and allowing the second portion for the user to determine the artist
# print(response.json())
# ## Integrating the json library
# ## This print output a bit better for user freindly
# import json
# import requests
# import sys
# if len(sys.argv) != 2:
# sys.exit()
# response = requests.get("https://itunes.apple.com/search?entity=song&limit=1&term=" + sys.argv[1]) # This is addressing the url and allowing the second portion for the user to determine the artist
# print(json.dumps(response.json(), indent = 2))
## Defining data you want to extract from the respective json file
## note that the output will extract 50 songs from the respective band inputted, in this case from the band 'weezer' after inputting in terminal 'python itunes.py weezer'
import json
import requests
import sys
if len(sys.argv) != 2:
sys.exit()
response = requests.get("https://itunes.apple.com/search?entity=song&limit=50&term=" + sys.argv[1]) # Note that here we changed in the url '...limit=1...' to '...limit=50...'
o = response.json()
for result in o["results"]:
print(result["trackName"])