recovered snapshot from suspended aaronjaworski710 (history unavailable)
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Register an MLH account for the GHW event (Rails form on events.mlh.com).
|
||||
Prereq: account signed in (cookies file), MLH profile/internal-auth completed.
|
||||
Usage: python event_reg.py <cookies-file> <github-username> [event-path]
|
||||
Default event: /events/14553-global-hack-week-hacktoberfest
|
||||
Retries on Heroku 503."""
|
||||
import json, http.client, re, ssl, urllib.parse, time, sys
|
||||
|
||||
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Safari/537.36"
|
||||
CKF = sys.argv[1] if len(sys.argv) > 1 else "cookies.txt"
|
||||
GHU = sys.argv[2] if len(sys.argv) > 2 else "your-github-username"
|
||||
EVENT = sys.argv[3] if len(sys.argv) > 3 else "/events/14553-global-hack-week-hacktoberfest"
|
||||
|
||||
class Cli:
|
||||
def __init__(self, ck, host):
|
||||
self.ck = ck; self.host = host
|
||||
self.ctx = ssl.create_default_context()
|
||||
self.conn = http.client.HTTPSConnection(host, 443, context=self.ctx, timeout=60)
|
||||
def _merge(self, r):
|
||||
jar = {}
|
||||
for p in self.ck.split("; "):
|
||||
if "=" in p:
|
||||
n, v = p.split("=", 1); jar[n] = v
|
||||
for k, v in r.getheaders():
|
||||
if k.lower() == "set-cookie":
|
||||
kv = v.split(";")[0]
|
||||
if "=" in kv:
|
||||
n, vv = kv.split("=", 1); jar[n] = vv
|
||||
self.ck = "; ".join(f"{n}={v}" for n, v in jar.items())
|
||||
def req(self, method, path, body=None, extra=None):
|
||||
hdrs = {"User-Agent": UA, "Accept": "text/html, application/xhtml+xml", "Cookie": self.ck}
|
||||
if extra: hdrs.update(extra)
|
||||
self.conn.request(method, path, body=body, headers=hdrs)
|
||||
r = self.conn.getresponse()
|
||||
data = r.read().decode(errors="replace")
|
||||
self._merge(r)
|
||||
return r.status, dict(r.headers), data
|
||||
|
||||
for attempt in range(3):
|
||||
C = Cli(open(CKF).read().strip(), "events.mlh.com")
|
||||
st, h, d = C.req("GET", EVENT + "?intent=register")
|
||||
i = d.find('id="new_participation"')
|
||||
if i < 0:
|
||||
print("NO FORM — account probably needs internal-auth first (profile steps). Status:", st,
|
||||
"url-len:", len(d)); break
|
||||
j = d.find("</form>", i)
|
||||
frag = d[i:j]
|
||||
tok = re.search(r'name="authenticity_token" value="([^"]+)"', frag).group(1)
|
||||
# question field names differ per event — auto-discover from the form fragment
|
||||
Q = "participation[event_questions_form]"
|
||||
form = {"authenticity_token": tok, "participation[status]": "completed", "commit": "Submit"}
|
||||
for name in re.findall(r'name="(participation\[event_questions_form\]\[[^\"]+\])"', frag):
|
||||
key = name.split("[")[-1].rstrip("]")
|
||||
if "github" in key: form[name] = GHU
|
||||
elif "country" in key: form[name] = "UA"
|
||||
elif "region" in key: form[name] = "Europe (EU)"
|
||||
elif "signup_source" in key: form[name] = "Email"
|
||||
elif "opt" in key or "understand" in key: form[name] = "true"
|
||||
else: form[name] = "1" # checkboxes/accepts
|
||||
body = urllib.parse.urlencode(form)
|
||||
st2, h2, d2 = C.req("POST", EVENT + "/registration", body,
|
||||
{"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Referer": "https://events.mlh.com" + EVENT + "?intent=register",
|
||||
"Origin": "https://events.mlh.com"})
|
||||
print(f"ATT{attempt} POST:", st2, "loc:", str(h2.get("Location", ""))[:160], flush=True)
|
||||
if st2 != 503:
|
||||
loc = h2.get("Location"); n = 0; cur = d2
|
||||
while loc and n < 5:
|
||||
n += 1
|
||||
host = "events.mlh.com" if "events.mlh.com" in loc else "www.mlh.com"
|
||||
if host != C.host: C = Cli(C.ck, host)
|
||||
path = loc.replace("https://" + host, "")
|
||||
st3, h3, cur = C.req("GET", path)
|
||||
print(f"FLW{n}:", st3, path[:110], "len", len(cur), flush=True)
|
||||
loc = h3.get("Location")
|
||||
open("event_reg_result.html", "w", encoding="utf-8").write(cur)
|
||||
txt = re.sub(r"<[^>]*>", "|", cur)
|
||||
parts = [p.strip() for p in txt.split("|") if p.strip() and 4 < len(p.strip()) < 90]
|
||||
seen = set()
|
||||
for p in parts[:60]:
|
||||
if any(k in p.lower() for k in ("regist", "check", "confirm", "complete", "thanks",
|
||||
"cursor", "promo", "error", "you're", "success")) and p not in seen:
|
||||
seen.add(p); print("T:", p, flush=True)
|
||||
break
|
||||
time.sleep(15)
|
||||
open(CKF, "w").write(C.ck)
|
||||
print("COOKIES:", len(C.ck), "host:", C.host, flush=True)
|
||||
Reference in New Issue
Block a user