Discuss Scratch

TheCloudDev
Scratcher
100+ posts

For Chiroyce

This is just code for chiroyce. pls ignore
import requests
import re
import websocket
import json
import time
import random
PROJECT_ID = 535640323
global l
l = 1
decoded = ""
OpSys = ""
encoded = ""
ws = websocket.WebSocket()
def login(username, password):
  headers = {
    "x-csrftoken": "a",
    "x-requested-with": "XMLHttpRequest",
    "Cookie": "scratchcsrftoken=a;scratchlanguage=en;",
    "referer": "https://scratch.mit.edu"
  }
  data = json.dumps({
    "username": username,
    "password": password
  })
  request = requests.post('https://scratch.mit.edu/login/', data=data, headers=headers)
  sessionId = re.search('"(.*)\"', request.headers['Set-Cookie']).group()
  return username, sessionId
def getVals(name):
    vname = '☁ ' + name
    response = requests.get('https://clouddata.scratch.mit.edu/logs?projectid='+ str(PROJECT_ID) + '&limit=100&offset=0')
    clouddata = response.json()
    global value
    global user
    for i in (clouddata):
        value = i
        if value['name'] == vname:
            value = value['value']
            l = 1
            decode(value)
            return(value)
def sendPacket(packet):
  ws.send(json.dumps(packet) + '\n') # send a packet of data
chars= ['', '', '', '', '', '', '', '', '', '\\', "'", 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '.', ' ', '_', ':', '<', '>', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '[', ']', '{', '}', ',', '/', '?',';']
def getStats(id):
  global loves
  global favs
  global views
  global status
  global OpSys
  status = ""
  response = requests.get("https://scratchdb.lefty.one/v3/project/info/" + str(id))
  clouddata = response.json()
  if clouddata == {'error':'post not found'}:
       status = 'Error: project not found on SDB v3'
  else:
    stats = clouddata['statistics']
    views = stats['views']
    loves = stats['loves']
    favs = stats['favorites']
    OpSys = clouddata['metadata']['user_agent']
    status = 'success!'
def encode (val):
    global encoded
    val = str(val).lower()
    letternum = l
    for i in range (1, len(str(val))+1):
       encoded = str(encoded) + str(chars.index(val[letternum-1])+1)
       letternum += 1
    encoded =  int(encoded + "00")
    return encoded
def decode (val):
    letternum = l
    global decoded
    decoded = ""
    idx = None
 
    while True:
        val = str(val)
        idx = val[letternum-1] + val[letternum]
        letternum += 2
        if int(idx) < 1:
            break
        decoded = decoded + chars[int(idx)-1]
    return decoded
def connect():
  global ws
  ws.connect('wss://clouddata.scratch.mit.edu', cookie='scratchsessionsid='+sessionId+';', origin='https://scratch.mit.edu', enable_multithread=True) # connect the websocket
  sendPacket({
    'method': 'handshake',
    'user': username,
    'project_id': str(PROJECT_ID)
  }) # to set variables you need to handshake first
def setCloudVar(variable, varval):
  try: 
    sendPacket({
      'method': 'set',
      'name': '☁ ' + variable,
      'value': str(varval),
      'user': username,
      'project_id': str(PROJECT_ID)
    })
    time.sleep(0.2)
  except BrokenPipeError:
    print('my pipe done broke') # sometimes you get a BrokenPipeError randomly and this fixes it
    connect()
    time.sleep(0.1)
username, sessionId = login('Username here', 'password here') # log in
connect() # connect
print('Connected to scratch.mit.edu via WSS. Listening for requests')
while True:
  print(random.randint(1,1000))
  olddata = getVals('Send')
  getVals('Send')
  if olddata != value:
      print('gettting stats..')
      getStats(decoded)
      print(status)
      if status == 'success!':
        print('sending data!')
        encoded = ""
        encode("Views: " + str(views))
        encode(" Loves: " + str(loves))
        encode(" Faves: " + str(favs))
        encode('z187234rbf' + str(random.randrange(1,1000)))
        setCloudVar('Return', encoded)
        encoded = ""
        encode("User Info: " + (str(OpSys)))
        print(encoded)
        setCloudVar('Return2', encoded)
        print('data sent!')
        print('Waiting for request.')
      else:
        encoded = ""
        encode('Error: Failed to fetch. Data not on Scratch DB V3')
        encode('z187234rbf' + str(random.randrange(1,1000)))
        setCloudVar('Return2', 0)
        setCloudVar('Return', encoded)
        print('Waiting for new request')
        

Last edited by TheCloudDev (May 27, 2021 12:18:30)


Hi! I'm TheCloudDev
wvj
Scratcher
1000+ posts

For Chiroyce

you better remove the project id from the code

TheCloudDev
Scratcher
100+ posts

For Chiroyce

wvj wrote:

you better remove the project id from the code
He's hosting the server for me. He needs the project ID for it to work doesn't he?

Hi! I'm TheCloudDev
wvj
Scratcher
1000+ posts

For Chiroyce

TheCloudDev wrote:

wvj wrote:

you better remove the project id from the code
He's hosting the server for me. He needs the project ID for it to work doesn't he?
now everyone can access the unshared project via turbowarp https://turbowarp.org/535640323

TheCloudDev
Scratcher
100+ posts

For Chiroyce

wvj wrote:

TheCloudDev wrote:

wvj wrote:

you better remove the project id from the code
He's hosting the server for me. He needs the project ID for it to work doesn't he?
now everyone can access the unshared project via turbowarp https://turbowarp.org/535640323
I know. It doesn't matter though. I'm gonna share it soon anyway.

Hi! I'm TheCloudDev

Powered by DjangoBB