Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import re
- import websocket
- import json
- import time
- import random
- PROJECT_ID = 535640323
- global l
- l = 1
- 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)
- })
- except BrokenPipeError:
- print('my pipe done broke')
- connect()
- time.sleep(0.1)
- username, sessionId = login('username goes here', 'password goes here') # log in
- connect() # connect
- print('Connected to scratch.mit.edu via WSS. Listening for requests')
- while True:
- olddata = getVals('Send')
- getVals('Send')
- if olddata != value:
- print('gettting stats..')
- print(decoded)
- 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("Author Info: " + (str(OpSys)))
- 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(encoded)
- print('Error failed to fetch.')
- print('Waiting for new request')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement