Skip to content

Instantly share code, notes, and snippets.

@prail
Created August 18, 2017 21:08
Show Gist options
  • Save prail/e9ec58723c60da32bfe25ad2f39e9d34 to your computer and use it in GitHub Desktop.
Save prail/e9ec58723c60da32bfe25ad2f39e9d34 to your computer and use it in GitHub Desktop.
A broken commenter for scratch.mit.edu.
#Write all of this in PHP so I can run it on 000webhost
import requests
import json
import warnings
warnings.filterwarnings("ignore")
USERNAME="mit"
PASSWORD="romney"
USERPAGE="kimjongun"
s=requests.Session()
HEADERS={
"X-Requested-With": "XMLHttpRequest",
"Referer":"https://scratch.mit.edu/"
}
s.get("https://scratch.mit.edu/csrf_token/",headers=HEADERS,verify=False)
CSRF_TOKEN=s.cookies.get("scratchcsrftoken")
HEADERS["X-CSRFToken"]=CSRF_TOKEN
data={
"username": USERNAME,
"password": PASSWORD,
"embed_captcha": True,
"timezone": "America/Los_Angeles",
"csrfmiddlewaretoken": CSRF_TOKEN
}
login=s.post("https://scratch.mit.edu/login/",json=data,headers=HEADERS,verify=False)
if login.status_code == 200:
#PROFILE=json.loads(requests.get("https://api.scratch.mit.edu/users/{}".format(USERNAME),verify=False).content.decode())
data={
"content":"Cow says moo.", #THIS TOO
"parent_id": '', #THIS NEEDS TO BE CHANGED
"commentee_id": '',
}
# vvv This needs changing.
HEADERS["Referer"]="https://scratch.mit.edu/users/{}".format(USERPAGE)
req=s.post("https://scratch.mit.edu/site-api/comments/user/{}/add/".format("TheUltimatum"),json=data,headers=HEADERS,verify=False)
print(req.status_code)
@prail
Copy link
Author

prail commented Sep 24, 2017

@bob1171 it was a script to log in to scratch with python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment