forked from l-JVN11-l/Scratch-4.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
96 lines (71 loc) · 2.52 KB
/
functions.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import requests
import os
import httpx
import json
from scratchclient import ScratchSession
def get_user_info(user):
url = requests.get(f"https://api.scratch.mit.edu/users/{user}/")
text = url.json()
user_wiwo = text['profile']['status']
user_bio = text['profile']['bio']
user_id = text['id']
location = text['profile']['country']
userJoined = text['history']['joined'].split('T')[0]
scratchteam = text['scratchteam']
response = httpx.get(f"https://scratchdb.lefty.one/v3/user/info/{ user }")
userData = json.loads(response.text)
followers = userData["statistics"]["followers"]
pfp_link = (
f'https://uploads.scratch.mit.edu/get_image/user/{user_id}_60x60.png')
return {
'pfpLink': pfp_link,
'userId': user_id,
'userBio': user_bio,
'userWiwo': user_wiwo,
'userLocation': location,
'userJoined': userJoined,
'userScratchTeam': scratchteam,
'userFollowersDB': followers
}
def user_found(user):
r = requests.head(f"https://api.scratch.mit.edu/users/{user}/")
if r.status_code == 404:
user_found = False
else:
user_found = True
return user_found
def scratcher(user):
url = requests.get(f"https://scratchdb.lefty.one/v3/user/info/{user}")
text = url.json()
scratcher = text["status"]
return scratcher
def featured_project_info(user):
url = requests.get(f"https://scratch.mit.edu/site-api/users/all/{user}/")
text = url.json()
FeaturedThumbnailURL = text["thumbnail_url"]
FeaturedLabel = text["featured_project_label_name"]
FeaturedTitle = text["featured_project_data"]["title"]
FeaturedPID = text['featured_project']
FeaturedCreator = text["featured_project_data"]["creator"]
return {
'featuredThumbnailURL': FeaturedThumbnailURL,
'featuredLabel': FeaturedLabel,
'featuredTitle': FeaturedTitle,
'featuredPID': FeaturedPID,
'featuredCreator': FeaturedCreator
}
def user_followers_list_username(user):
url = requests.get(f"https://api.scratch.mit.edu/users/jvn11/followers/")
text = url.json()
followers = []
for i in (range(0, len(text))):
followers.append(text[i]['username'])
return {
'followers': followers,
'length': len(followers)
}
def login(username,password):
session = ScratchSession(username, password)
def get_message_count(username):
count = requests.get(f'https://api.scratch.mit.edu/users/{username}/messages/count').json()['count']
return count