Discuss Scratch

mybearworld
Scratcher
1000+ posts

My "random user/project/etc" programs

Use Python 3 to execute these.

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}")
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:
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}")
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.

Last edited by mybearworld (July 28, 2021 16:25:54)


Scratch added a Getting Started tutorial for deaf people!
mybearworld
Scratcher
1000+ posts

My "random user/project/etc" programs


Scratch added a Getting Started tutorial for deaf people!
mybearworld
Scratcher
1000+ posts

My "random user/project/etc" programs


Scratch added a Getting Started tutorial for deaf people!
LankyBox01
Scratcher
1000+ posts

My "random user/project/etc" programs

Actually advanced topics is a better fit for this

btw nodejs version pls?

Do you have trouble with scratch slang? Check this awesome site out!

I'm a red panda btw
mybearworld
Scratcher
1000+ posts

My "random user/project/etc" programs

LankyBox01 wrote:

[View post]
Actually advanced topics is a better fit for this
I'll report it to be moved then.

LankyBox01 wrote:

[View post]
btw nodejs version pls?
Not sure what that is, and I can't get normal JS to work…

Scratch added a Getting Started tutorial for deaf people!
Chiroyce
Scratcher
1000+ posts

My "random user/project/etc" programs

mybearworld wrote:

Random User:
...read())["community_newest_projects"][0]["id"])...
isn't that for projects?

edit - ok so it takes a username from the latest projects ..

Last edited by Chiroyce (July 29, 2021 16:22:11)


| Boy | 13 | Python | ATer |  Tech | Cars | Procrastinator | Forums | Cricket | ☁️ Cloud |

5fdb2e83ca5a134289edeb294044abb23578eeb6d0d851cca9dd976b38ec6508


I FOUND IT!!! https://scratch.mit.edu/adminpanel/adminpanel.png


mybearworld
Scratcher
1000+ posts

My "random user/project/etc" programs

Chiroyce wrote:

[View post]

mybearworld wrote:

Random User:
...read())["community_newest_projects"][0]["id"])...
isn't that for projects?

edit - ok so it takes a username from the latest projects ..
It generates a random project, from 1 to the latest, and if it exists, it gets it's creator's username.

Scratch added a Getting Started tutorial for deaf people!
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).
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

Raihan142857 wrote:

[View post]
This isn't really random users/projects/posts but ok
What? I can't really go more random than with the “random” module.

Scratch added a Getting Started tutorial for deaf people!
Raihan142857
Scratcher
1000+ posts

My "random user/project/etc" programs

mybearworld wrote:

Raihan142857 wrote:

[View post]
This isn't really random users/projects/posts but ok
What? I can't really go more random than with the “random” module.
Oops, I misread your code - never mind.

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

wvj wrote:

[View post]
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")
1. It uses pinging, if I understand correctly, what is not allowed.
2. It uses scratchclient what is not built in so I'd not use it anyways xD

Scratch added a Getting Started tutorial for deaf people!

Powered by DjangoBB

Standard | Mobile