-
Notifications
You must be signed in to change notification settings - Fork 0
/
case3.py
69 lines (57 loc) · 1.76 KB
/
case3.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import requests
import os
url = "https://5hyqtreww2.execute-api.eu-north-1.amazonaws.com/artists/"
r = requests.get(url)
celebrityDictionary = r.json()
line = "-----------------------------------\n"
artists = [i["name"] for i in celebrityDictionary["artists"]]
def errorproof():
try:
input("Press enter to continue.")
except KeyboardInterrupt:
pass
def printartists():
print(line)
for i in celebrityDictionary["artists"]:
print("|", i["name"])
print(line)
errorproof()
def viewartist():
artistname = ""
while artistname.title() not in artists:
try:
artistname = input("Artist name > ")
except KeyboardInterrupt:
print("\nInvalid input")
id = ""
r = requests.get(url)
celebrityDictionary = r.json()
for i in celebrityDictionary["artists"]:
if i["name"] == artistname.title():
id = i["id"]
break
fetchedurl = url+id
p = requests.get(fetchedurl)
artistinfo = p.json()["artist"]
print(line+"\n"+artistinfo["name"]+"\n"+line)
for key, val in artistinfo.items():
if key != "name":
print(key.title()+"")
for i in val:
print("-", i)
print(line)
errorproof()
instructions = {
"List": printartists,
"View": viewartist,
"Exit": exit,
}
while True:
errormessage = ""
os.system("cls")
print(line+"List | List artists\nView | View artist profile\nExit | Exit application\n"+errormessage+line)
try:
whattodo = input(">> ").title()
instructions[whattodo]()
except (KeyError, KeyboardInterrupt, ValueError):
errormessage = line+"\nError: Invalid input. Try again\n"