Advertisement
paster442

chiroyce

May 27th, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.47 KB | None | 0 0
  1. import requests
  2. import re
  3. import websocket
  4. import json
  5. import time
  6. import random
  7. PROJECT_ID = 535640323
  8. global l
  9. l = 1
  10. OpSys = ""
  11. encoded = ""
  12. ws = websocket.WebSocket()
  13. def login(username, password):
  14.   headers = {
  15.     "x-csrftoken": "a",
  16.     "x-requested-with": "XMLHttpRequest",
  17.     "Cookie": "scratchcsrftoken=a;scratchlanguage=en;",
  18.     "referer": "https://scratch.mit.edu"
  19.   }
  20.   data = json.dumps({
  21.     "username": username,
  22.     "password": password
  23.   })
  24.   request = requests.post('https://scratch.mit.edu/login/', data=data, headers=headers)
  25.   sessionId = re.search('"(.*)\"', request.headers['Set-Cookie']).group()
  26.   return username, sessionId
  27. def getVals(name):
  28.     vname = '☁ ' + name
  29.     response = requests.get('https://clouddata.scratch.mit.edu/logs?projectid='+ str(PROJECT_ID) + '&limit=100&offset=0')
  30.     clouddata = response.json()
  31.     global value
  32.     global user
  33.     for i in (clouddata):
  34.         value = i
  35.         if value['name'] == vname:
  36.             value = value['value']
  37.             l = 1
  38.             decode(value)
  39.             return(value)
  40. def sendPacket(packet):
  41.   ws.send(json.dumps(packet) + '\n') # send a packet of data
  42. 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', '+', '-', '.', ' ', '_', ':', '<', '>', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '[', ']', '{', '}', ',', '/', '?',';']
  43. def getStats(id):
  44.   global loves
  45.   global favs
  46.   global views
  47.   global status
  48.   global OpSys
  49.   status = ""
  50.   response = requests.get("https://scratchdb.lefty.one/v3/project/info/" + str(id))
  51.   clouddata = response.json()
  52.   if clouddata == {'error':'post not found'}:
  53.        status = 'Error: project not found on SDB v3'
  54.   else:
  55.     stats = clouddata['statistics']
  56.     views = stats['views']
  57.     loves = stats['loves']
  58.     favs = stats['favorites']
  59.     OpSys = clouddata['metadata']['user_agent']
  60.     status = 'success!'
  61. def encode (val):
  62.     global encoded
  63.     val = str(val).lower()
  64.     letternum = l
  65.     for i in range (1, len(str(val))+1):
  66.        encoded = str(encoded) + str(chars.index(val[letternum-1])+1)
  67.        letternum += 1
  68.     encoded =  int(encoded + "00")
  69.     return encoded
  70. def decode (val):
  71.     letternum = l
  72.     global decoded
  73.     decoded = ""
  74.     idx = None
  75.  
  76.     while True:
  77.         val = str(val)
  78.         idx = val[letternum-1] + val[letternum]
  79.         letternum += 2
  80.         if int(idx) < 1:
  81.             break
  82.         decoded = decoded + chars[int(idx)-1]
  83.     return decoded
  84. def connect():
  85.   global ws
  86.   ws.connect('wss://clouddata.scratch.mit.edu', cookie='scratchsessionsid='+sessionId+';', origin='https://scratch.mit.edu', enable_multithread=True) # connect the websocket
  87.   sendPacket({
  88.     'method': 'handshake',
  89.     'user': username,
  90.     'project_id': str(PROJECT_ID)
  91.   }) # to set variables you need to handshake first
  92. def setCloudVar(variable, varval):
  93.   try:
  94.     sendPacket({
  95.       'method': 'set',
  96.       'name': '☁ ' + variable,
  97.       'value': str(varval),
  98.       'user': username,
  99.       'project_id': str(PROJECT_ID)
  100.     })
  101.   except BrokenPipeError:
  102.     print('my pipe done broke')
  103.     connect()
  104.     time.sleep(0.1)
  105. username, sessionId = login('username goes here', 'password goes here') # log in
  106.  
  107.  
  108.  
  109.  
  110.  
  111. connect() # connect
  112. print('Connected to scratch.mit.edu via WSS. Listening for requests')
  113. while True:
  114.   olddata = getVals('Send')
  115.   getVals('Send')
  116.   if olddata != value:
  117.       print('gettting stats..')
  118.       print(decoded)
  119.       getStats(decoded)
  120.       print(status)
  121.       if status == 'success!':
  122.         print('sending data!')
  123.         encoded = ""
  124.         encode("Views: " + str(views))
  125.         encode(" Loves: " + str(loves))
  126.         encode(" Faves: " + str(favs))
  127.         encode('z187234rbf' + str(random.randrange(1,1000)))
  128.         setCloudVar('Return', encoded)
  129.         encoded = ""
  130.         encode("Author Info: " + (str(OpSys)))
  131.         setCloudVar('Return2', encoded)
  132.         print('data sent!')
  133.         print('Waiting for request.')
  134.       else:
  135.         encoded = ""
  136.         encode('Error: Failed to fetch. Data not on Scratch DB V3')
  137.         encode('z187234rbf' + str(random.randrange(1,1000)))
  138.         setCloudVar('Return2', 0)
  139.         setCloudVar('Return', encoded)
  140.         print(encoded)
  141.         print('Error failed to fetch.')
  142.         print('Waiting for new request')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement