Tcl Source Code

Artifact [6f4f35cea9]
Login

Artifact 6f4f35cea9a2444b1148ff9bbfcbf302f4199f30a2dd0f0ec20a608df995378e:

Attachment "buienradar.tcl" to ticket [338d979f5b] added by sbron 2020-07-24 20:07:39. (unpublished)
#!/usr/bin/tclsh

package require http
package require tls

http::register https 443 tls::socket

set url https://image.buienradar.nl/2.0/image/sprite/RadarMapRainNL

set tok [http::geturl $url]
set code [http::ncode $tok]
if {$code in {301 302}} {
    set str [lsearch -nocase -exact -inline [http::meta $tok] location]
    set loc [dict get [http::meta $tok] $str]
    http::cleanup $tok
    set tok [http::geturl $loc]
    set code [http::ncode $tok]
}
dict for {key val} [http::meta $tok] {
    puts "$key $val"
}
set f [open /tmp/buienradar.png wb]
puts -nonewline $f [http::data $tok]
http::cleanup $tok