Now the problem is, it takes about 20-40sec to get the data which are downloaded in 1sec in syncronous mode. Now you might wonder why I dont use syncronous then... well the reasons should be obvious. I dont want to get the bot stuck just because the site is not avaible or really slow.
My idea was:
Code: Select all
set fd [open "|tclsh8.4" r+]
puts $fd "package require http 2.4"
if {[info exists wetter(useragent)]} {
puts $fd "::http::config -useragent $wetter(useragent)"
}
puts $fd "puts -nonewline stdout \[array get \[::http::geturl $query -headers {Host www.wetter.com Connection close}\]\]"
fconfigure $fd -blocking 0
putlog "Log: [read $fd]"
fileevent $fd readable [list getwetter:cb $fd]
PS: Yes, I thought about using lynx, but a) it doesnt return all infos like the http state var does b) lynx is not installed on every shell (wget might be hard to capture when its finished and creates unncessary hard disc usage)
simple example:
Code: Select all
~/eggi$ tclsh
% open |tclsh r+
file5
% puts file5 "puts stdout muh"
% read file5
PPS: oh yeah, my first idea was using -blocksize 65532 (file is around 60kb) which made it about twice as fast, but ~15sec is still much too slow.