Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -64,7 +64,56 @@ def drive():
|
|
| 64 |
ip = request.remote_addr
|
| 65 |
print(f"アクセスIP: {ip}")
|
| 66 |
return redirect("https://drive.google.com/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
@app.route("/channel-io-managers")
|
| 69 |
def get_managers():
|
| 70 |
limit = request.args.get("limit")
|
|
|
|
| 64 |
ip = request.remote_addr
|
| 65 |
print(f"アクセスIP: {ip}")
|
| 66 |
return redirect("https://drive.google.com/")
|
| 67 |
+
@app.route("/scratch_login", methods=["POST"])
|
| 68 |
+
def scratch_login():
|
| 69 |
+
data = request.json
|
| 70 |
+
username = data.get("username")
|
| 71 |
+
password = data.get("password")
|
| 72 |
|
| 73 |
+
if not username or not password:
|
| 74 |
+
return jsonify({"error": "username と password を指定してください"}), 400
|
| 75 |
+
|
| 76 |
+
# ① CSRF Token を取得する
|
| 77 |
+
token_url = "https://corsproxy.io?url=https://scratch.mit.edu/csrf_token/"
|
| 78 |
+
session = requests.Session()
|
| 79 |
+
token_resp = session.get(token_url)
|
| 80 |
+
|
| 81 |
+
if token_resp.status_code != 200:
|
| 82 |
+
return jsonify({"error": "CSRF トークン取得失敗"}), 500
|
| 83 |
+
|
| 84 |
+
# Cookie の scratchcsrftoken を取得
|
| 85 |
+
scratchcsrftoken = session.cookies.get("scratchcsrftoken")
|
| 86 |
+
|
| 87 |
+
if not scratchcsrftoken:
|
| 88 |
+
return jsonify({"error": "CSRF トークンがクッキーにありません"}), 500
|
| 89 |
+
|
| 90 |
+
# ② POST でログイン
|
| 91 |
+
login_url = "https://scratch.mit.edu/accounts/login/"
|
| 92 |
+
|
| 93 |
+
headers = {
|
| 94 |
+
"Content-Type": "application/json",
|
| 95 |
+
"x-csrftoken": scratchcsrftoken,
|
| 96 |
+
"Referer": "https://scratch.mit.edu/",
|
| 97 |
+
"User-Agent": "Mozilla/5.0"
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
payload = {
|
| 101 |
+
"username": username,
|
| 102 |
+
"password": password,
|
| 103 |
+
"useMessages": True
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
login_resp = session.post(login_url, json=payload, headers=headers)
|
| 107 |
+
|
| 108 |
+
try:
|
| 109 |
+
result_json = login_resp.json()
|
| 110 |
+
except Exception:
|
| 111 |
+
result_json = {"error": "JSON パース失敗", "text": login_resp.text}
|
| 112 |
+
|
| 113 |
+
return jsonify({
|
| 114 |
+
"scratchcsrftoken": scratchcsrftoken,
|
| 115 |
+
"login_response": result_json
|
| 116 |
+
})
|
| 117 |
@app.route("/channel-io-managers")
|
| 118 |
def get_managers():
|
| 119 |
limit = request.args.get("limit")
|