fn absolute_url(location) {
    if location.starts_with("/") { return "https://realm.micro1.ai" + location }
    return location
}

fn first_script_src(html) {
    return html.split("<script")[1].split("src=\"")[1].split("\"")[0]
}

fn prefix(text, count) {
    let mut out = ""
    let mut i = 0
    while i < count && i < text.len() {
        out = out + text[i]
        i = i + 1
    }
    return out
}

fn main() {
    let first = http_get("https://realm.micro1.ai/login").unwrap()
    let page = http_get(absolute_url(first.headers.location)).unwrap()
    let source = http_get(absolute_url(first_script_src(page.body))).unwrap().body
    let parts = source.split("function(s,r,i)")
    println("module-like parts: " + str(parts.len()))
    let ids = [0, 1, 12, 31, 32, 33, 39, 50, 109]
    let mut i = 0
    while i < ids.len() {
        let id = ids[i]
        println("module " + str(id))
        println(prefix(parts[id + 1], 2500))
        i = i + 1
    }
}
