Skip to content

Commit 4fb4a04

Browse files
authored
add new utility
1 parent de197da commit 4fb4a04

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

src/wrapper.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
while True:
1010
# get api wrapping utility
11-
utility = input("Utility [user-projects-wrapper, follower-wrapping-utility, exit]: ")
11+
utility = input("Utility? [user-projects-wrapper, follower-wrapper, favorite-projects-wrapper, exit]: ")
1212

1313
if utility == "user-projects-wrapper":
1414
# url
@@ -21,7 +21,7 @@
2121
# display info
2222
for project in data:
2323
title = project.get('title', 'N/A')
24-
description = project.get('description', 'No description available')
24+
description = project.get('description')
2525
loves = project.get('stats', {}).get('loves', 0)
2626
favorites = project.get('stats', {}).get('favorites', 0)
2727
views = project.get('stats', {}).get('views', 0)
@@ -45,7 +45,7 @@
4545
print("=" * 50)
4646
print("\n")
4747

48-
elif utility == "follower-wrapping-utility":
48+
elif utility == "follower-wrapper":
4949
# url
5050
url = f"https://api.scratch.mit.edu/users/{username}/followers/"
5151
# get data
@@ -66,6 +66,39 @@
6666
# If you want to fetch and display more follower details, add additional fields here
6767
print("=" * 50)
6868
print("\n")
69+
70+
elif utility == "favorite-projects-wrapper":
71+
# url
72+
url = f"https://api.scratch.mit.edu/users/{username}/favorites/"
73+
# get data
74+
response = urlib.request.urlopen(url)
75+
data = json.loads(response.read())
76+
# display info
77+
print("=" * 50)
78+
print(f"Favorite projects for {username}")
79+
print("=" * 50)
80+
81+
for project in data:
82+
title = project.get('title', 'N/A')
83+
description = project.get('description')
84+
85+
print("=" * 50)
86+
print("PROJECT NAME")
87+
print("-" * 50)
88+
print(f"{title}")
89+
90+
print("\nDESCRIPTION")
91+
print("-" * 50)
92+
print(f"{description}")
93+
94+
print("\nSTATS")
95+
print("-" * 50)
96+
print(f"Hearts: {loves}")
97+
print(f"Stars: {favorites}")
98+
print(f"Views: {views}")
99+
print(f"Remixes: {remixes}")
100+
print("=" * 50)
101+
print("\n")
69102

70103
elif utility == "exit":
71104
os.exit()

0 commit comments

Comments
 (0)