#!/usr/bin/env python3
"""Find the a2 enum (LoginPage) definition and the string value of Dashboard."""
import urllib.request, re
ORIGIN = "https://app.curogram.com/"
def get(u):
    req = urllib.request.Request(u, headers={"User-Agent": "Mozilla/5.0"})
    return urllib.request.urlopen(req, timeout=20).read().decode("utf-8", "replace")
t = get(ORIGIN + "main.6c33764396ecdff8.js")
# enum member assignment forms: .Dashboard="..." or Dashboard="..." or Dashboard:"..."
for m in re.finditer(r'Dashboard\s*[=:]\s*["\']([^"\']+)["\']', t):
    i = m.start()
    print("DASH", m.group(1), "||", re.sub(r"\s+", " ", t[max(0, i-70):i+30])[-90:])
# Find where a2 is defined: (function(o){o.Dashboard=...})(a2||(a2={}))
for m in re.finditer(r'\(\s*function\s*\(\s*(\w+)\s*\)\s*\{[^}]*Dashboard[^}]*\}\s*\)\s*\(\s*(\w+)', t):
    print("ENUMDEF", re.sub(r"\s+", " ", m.group(0))[:300])
# a2 token def: a2 = something / var a2
for m in re.finditer(r'\b(\w{1,4})\.Dashboard\s*=\s*["\']([^"\']+)["\']', t):
    print("MEMBER", m.group(1), "Dashboard=", m.group(2))
print("done")
