Skip to content

Commit f24ce5d

Browse files
authored
start making api wrapping utilitys.
1 parent 0210980 commit f24ce5d

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

src/wrapper.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,50 @@
1-
# aka the main file
1+
# main file
2+
import urllib.request
3+
import json
4+
import os
5+
6+
# get username
7+
username = input("Enter Scratch username: ")
8+
9+
while True:
10+
# get api wrapping utility
11+
utility = input("Utility [user-projects-wrapper, exit]: ")
12+
13+
if utility == "user-projects-wrapper":
14+
# url
15+
url = f"https://api.scratch.mit.edu/users/{username}/projects/"
16+
17+
# fetch daaataaaa
18+
response = urllib.request.urlopen(url)
19+
data = json.loads(response.read())
20+
21+
# display info
22+
for project in data:
23+
title = project.get('title', 'N/A')
24+
description = project.get('description', 'No description available')
25+
loves = project.get('stats', {}).get('loves', 0)
26+
favorites = project.get('stats', {}).get('favorites', 0)
27+
views = project.get('stats', {}).get('views', 0)
28+
remixes = project.get('remix', {}).get('count', 0)
29+
30+
print("=" * 50)
31+
print("PROJECT NAME")
32+
print("-" * 50)
33+
print(f"{title}")
34+
35+
print("\nDESCRIPTION")
36+
print("-" * 50)
37+
print(f"{description}")
38+
39+
print("\nSTATS")
40+
print("-" * 50)
41+
print(f"Hearts: {loves}")
42+
print(f"Stars: {favorites}")
43+
print(f"Views: {views}")
44+
print(f"Remixes: {remixes}")
45+
print("=" * 50)
46+
print("\n")
47+
if utility == "exit":
48+
os.exit()
49+
else:
50+
print("thats not an option right now!")

0 commit comments

Comments
 (0)