|
8 | 8 |
|
9 | 9 | while True: |
10 | 10 | # 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]: ") |
12 | 12 |
|
13 | 13 | if utility == "user-projects-wrapper": |
14 | 14 | # url |
|
21 | 21 | # display info |
22 | 22 | for project in data: |
23 | 23 | title = project.get('title', 'N/A') |
24 | | - description = project.get('description', 'No description available') |
| 24 | + description = project.get('description') |
25 | 25 | loves = project.get('stats', {}).get('loves', 0) |
26 | 26 | favorites = project.get('stats', {}).get('favorites', 0) |
27 | 27 | views = project.get('stats', {}).get('views', 0) |
|
45 | 45 | print("=" * 50) |
46 | 46 | print("\n") |
47 | 47 |
|
48 | | - elif utility == "follower-wrapping-utility": |
| 48 | + elif utility == "follower-wrapper": |
49 | 49 | # url |
50 | 50 | url = f"https://api.scratch.mit.edu/users/{username}/followers/" |
51 | 51 | # get data |
|
66 | 66 | # If you want to fetch and display more follower details, add additional fields here |
67 | 67 | print("=" * 50) |
68 | 68 | 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") |
69 | 102 |
|
70 | 103 | elif utility == "exit": |
71 | 104 | os.exit() |
|
0 commit comments