Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » My "random user/project/etc" programs
- mybearworld
- Scratcher
1000+ posts
My "random user/project/etc" programs
Use Python 3 to execute these.
Random User:
Random Project:
Random Studio:
Note that there is no API for newest studios. You'll have to create one once in a while and change the “studioID” variable to it's ID if you want more up-to-date studios to be possible to be generated..
Random Forum Post:
Note that there is no API for newest posts. You'll have to create one once in a while and change the “postID” variable to it's ID if you want more up-to-date forum posts to be possible to be generated.
Any suggestions? Feel free to let me know.
Random User:
import urllib.request, json, random, webbrowser x = 0 def userOf(pid): try: return json.loads(urllib.request.urlopen(f"https://api.scratch.mit.edu/projects/{pid}").read())["author"]["username"] except: return None while userOf(x) == None: x = random.randint(1, json.loads(urllib.request.urlopen("https://api.scratch.mit.edu/proxy/featured/").read())["community_newest_projects"][0]["id"]) webbrowser.open_new_tab(f"https://scratch.mit.edu/users/{userOf(x)}")
Random Project:
import urllib.request, json, random, webbrowser x = 0 def projectExists(pid): try: urllib.request.urlopen(f"https://api.scratch.mit.edu/projects/{pid}") except: return False return True while not projectExists(x): x = random.randint(1, json.loads(urllib.request.urlopen("https://api.scratch.mit.edu/proxy/featured/").read())["community_newest_projects"][0]["id"]) webbrowser.open_new_tab(f"https://scratch.mit.edu/projects/{x}")
Random Studio:
import urllib.request, json, random, webbrowser x = 0 studioID = 30122289 def studioExists(pid): try: urllib.request.urlopen(f"https://api.scratch.mit.edu/studios/{pid}") except: return False return True while not studioExists(x): x = random.randint(1, studioID) webbrowser.open_new_tab(f"https://scratch.mit.edu/studios/{x}")
Random Forum Post:
import urllib.request, json, random, webbrowser x = 0 postID = 5475179 def postAvailable(pid): try: urllib.request.urlopen(f"https://scratch.mit.edu/discuss/post/{pid}") except: return False return True while not postAvailable(x): x = random.randint(1, postID) webbrowser.open_new_tab(f"https://scratch.mit.edu/discuss/post/{x}")
Any suggestions? Feel free to let me know.
Last edited by mybearworld (July 28, 2021 16:25:54)
Signatures are the only place where assets links still work.
- mybearworld
- Scratcher
1000+ posts
My "random user/project/etc" programs
Signatures are the only place where assets links still work.
- mybearworld
- Scratcher
1000+ posts
My "random user/project/etc" programs
Signatures are the only place where assets links still work.
- LankyBox01
- Scratcher
1000+ posts
My "random user/project/etc" programs
Actually advanced topics is a better fit for this
btw nodejs version pls?
btw nodejs version pls?
- mybearworld
- Scratcher
1000+ posts
My "random user/project/etc" programs
[View post] Actually advanced topics is a better fit for thisI'll report it to be moved then.
[View post]btw nodejs version pls?Not sure what that is, and I can't get normal JS to work…
Signatures are the only place where assets links still work.
- Chiroyce
- Scratcher
1000+ posts
My "random user/project/etc" programs
Random User:isn't that for projects?...read())["community_newest_projects"][0]["id"])...
edit - ok so it takes a username from the latest projects ..
Last edited by Chiroyce (July 29, 2021 16:22:11)
April Fools' topics:
— New Buildings in Scratch's headquarters
— Give every Scratcher an M1 MacBook Air
— Scratch should let users edit other Scratchers' projects
— Make a statue for Jeffalo
— Scratch Tech Tips™
— Make a Chiroyce statue emoji
<img src=“x” onerror=“alert('XSS vulnerability discovered')”>
this is a test sentence
- mybearworld
- Scratcher
1000+ posts
My "random user/project/etc" programs
[View post]It generates a random project, from 1 to the latest, and if it exists, it gets it's creator's username.Random User:isn't that for projects?...read())["community_newest_projects"][0]["id"])...
edit - ok so it takes a username from the latest projects ..
Signatures are the only place where assets links still work.
- Raihan142857
- Scratcher
1000+ posts
My "random user/project/etc" programs
This isn't really random users/projects/posts but ok
I modified them a bit and rewrote them in node (now it's actually random posts/projects/studios/users, sort of).
I modified them a bit and rewrote them in node (now it's actually random posts/projects/studios/users, sort of).
const fetch = require('node-fetch'); // estimate newest project ID async function newestProjectID() { const res = await (await fetch('https://api.scratch.mit.edu/proxy/featured/')).json(); return res.community_newest_projects[0].id; } // estimate newest studio ID, not very accurate sadly async function newestStudioID() { const res = await (await fetch('https://api.scratch.mit.edu/proxy/featured/')).json(); return res.community_featured_studios[0].id; } // random project async function randomProject() { const newest = await newestProjectID(); while (true) { const project = Math.floor(Math.random() * newest); const res = await (await fetch(`https://api.scratch.mit.edu/projects/${project}`)).json(); if (!res.code) return res; } } // random user (there's no way to get users by ID) async function randomUser() { const user = (await randomProject()).author.username; return await (await fetch(`https://api.scratch.mit.edu/users/${user}`)).json(); } // random studio async function randomStudio() { const newest = await newestStudioID(); while (true) { const studio = Math.floor(Math.random() * newest); const res = await (await fetch(`https://api.scratch.mit.edu/studios/${studio}`)).json(); if (!res.code) return res; } } // random forum post, thanks scratchdb async function randomForumPost() { const res = await (await fetch('https://scratchdb.lefty.one/v3/forum/search?q=&o=newest')).json(); const post = Math.floor(Math.random() * res.posts[0].id); return await (await fetch(`https://scratchdb.lefty.one/v3/forum/post/info/${post}`)).json(); }
I use scratch.
GF: I'll dump you. BF: hex dump or binary dump?
- mybearworld
- Scratcher
1000+ posts
My "random user/project/etc" programs
[View post]This isn't really random users/projects/posts but okWhat? I can't really go more random than with the “random” module.
Signatures are the only place where assets links still work.
- Raihan142857
- Scratcher
1000+ posts
My "random user/project/etc" programs
Oops, I misread your code - never mind.[View post]This isn't really random users/projects/posts but okWhat? I can't really go more random than with the “random” module.
I use scratch.
GF: I'll dump you. BF: hex dump or binary dump?
- wvj
- Scratcher
1000+ posts
My "random user/project/etc" programs
You can also do this to find a random user, this code doesn't require for a user to have shared a project
# run this program and check your profile comments from scratchclient import * from random import * from time import * start_time = time() session = ScratchSession("username", "password") # replace this with your username and password def antiSpam(): empty_string = "" for i in range(1, randint(1, 501)): empty_string += "\u00AD" # soft hyphen to avoid spam return empty_string parent_id = "" commentee_id = randint(139, 79000000) session.get_user("mybearworld").post_comment(antiSpam(), parent_id, commentee_id) print("Execution time: " + str(round((time() - start_time), 3)) + " s")
Last edited by wvj (July 29, 2021 22:45:16)
- mybearworld
- Scratcher
1000+ posts
My "random user/project/etc" programs
[View post]You can also do this to find a random user, this code doesn't require for a user to have shared a project1. It uses pinging, if I understand correctly, what is not allowed.# run this program and check your profile comments from scratchclient import * from random import * from time import * start_time = time() session = ScratchSession("username", "password") # replace this with your username and password def antiSpam(): empty_string = "" for i in range(1, randint(1, 501)): empty_string += "\u00AD" # soft hyphen to avoid spam return empty_string parent_id = "" commentee_id = randint(139, 79000000) session.get_user("mybearworld").post_comment(antiSpam(), parent_id, commentee_id) print("Execution time: " + str(round((time() - start_time), 3)) + " s")
2. It uses scratchclient what is not built in so I'd not use it anyways xD
edit: ah
Last edited by mybearworld (May 4, 2023 11:21:17)
Signatures are the only place where assets links still work.
- therealkakallika
- Scratcher
100+ posts
My "random user/project/etc" programs
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
NameError: name ‘userOf’ is not defined
File “<stdin>”, line 1, in <module>
NameError: name ‘userOf’ is not defined
(0_0::sound) // this is Tom, he is protecting himself from evil kumquats from eating my signature
(Θ_Θ::)//this is Sergey who protects everyone (in my signature) from evil kumquats
(-_-)//this is Mu. He protects Sergey if he can't
()(){}::events//this is Xi. She protects Mu if he can't
<1_1::motion>//this is Tubesodaeafy, named after Tubesodaeafy. He protects Xi if even she can't
(>:\()//evil kumquat
<(0_0::sound) < (>:\()>//oh no
<<1_1::motion> < (>:\()>//oh no, even he is weak
<((0_0::sound) + ((Θ_Θ::) + ((-_-) + ((()(){}::events stack) + <1_1::motion>)))) < (>:\()>//no way
<((0_0::sound) * ((Θ_Θ::) * ((-_-) * ((()(){}::events stack) * <1_1::motion>)))) < (>:\()>//no way
<((0_0::sound) ^ ((Θ_Θ::) ^ ((-_-) ^ ((()(){}::events stack) ^ <1_1::motion>::operators)::operators)::operators)::operators) > (>:\()>//yes way
0 0{(0_0::sound)
(Θ_Θ::)
(-_-)
()(){}::events
<1_1::motion>}::#00ff00 //alligator is eating us!
- Discussion Forums
- » Advanced Topics
- » My "random user/project/etc" programs