if {![info exists LastNews]} {
variable LastNews {}
timer 1 nerikes_auto
}
if {![info exists kolla]} {
set kolla 1
timer 1 nerikes_auto
}

proc nerikes_auto {} {
set sock [socket -async www.nerikes.se 80]
fconfigure $sock -buffering line
puts $sock "GET /textversion/senastenytt_idag.asp HTTP/1.0"
puts $sock "Host: www.nerikes.se"
puts $sock "User-Agent: Mozilla??"
puts $sock ""

flush $sock
set d 1
set l 1
set o 1
set n 1
while {![eof $sock]} {
gets $sock line
if {[regexp -all {<p class="brodtext">Ännu inga nyheter i dag...</p>} $line]} {
set nonews 1
}
if {[regexp -all {<span class="datum">(.*?)</span>} $line]} {
regsub -all {(<.+?>)} $line "" line
regsub -all {\t} $line "" line
regsub -all {&nbsp;} $line " " line
regsub -all "&aring;" $line "å" line
regsub -all "&auml;" $line "ä" line
regsub -all "&ouml;" $line "ö" line
regsub -all "&Aring;" $line "Å" line
regsub -all "&Auml;" $line "Ä" line
regsub -all "&Ouml;" $line "Ö" line
regsub -all "&quot;" $line {"} line
regsub -all "&#039;" $line {'} line
set datum($d) $line
incr d
}
if {[regexp -all {<a href="(.*?)" title=".*" class="rubrik">(.*?)<b>} $line _ lenk]} {
regsub -all "&aring;" $lenk "å" lenk
regsub -all "&auml;" $lenk "ä" lenk
regsub -all "&ouml;" $lenk "ö" lenk
regsub -all "&Aring;" $lenk "Å" lenk
regsub -all "&Auml;" $lenk "Ä" lenk
regsub -all "&Ouml;" $lenk "Ö" lenk
regsub -all "&quot;" $lenk {"} lenk
regsub -all "&#039;" $lenk {'} lenk
regsub -all {(<.+?>)} $lenk "" lenk
regsub -all {\t} $lenk "" lenk
set link($l) "http://www.nerikes.se/$lenk"
incr l
}
if {[regexp -all {<b>(.*?)</b></a>} $line _ nyh]} {
regsub -all "&aring;" $nyh "å" nyh
regsub -all "&auml;" $nyh "ä" nyh
regsub -all "&ouml;" $nyh "ö" nyh
regsub -all "&Aring;" $nyh "Å" nyh
regsub -all "&Auml;" $nyh "Ä" nyh
regsub -all "&Ouml;" $nyh "Ö" nyh
regsub -all "&quot;" $nyh {"} nyh
regsub -all "&#039;" $nyh {'} nyh
regsub -all {(<.+?>)} $nyh "" nyh
set nyhet($n) "$nyh"
incr n
}
if {[regexp -all {<span class="ort">(.*?)</span>} $line]} {
regsub -all {(<.+?>)} $line "" line
regsub -all {\t} $line "" line
regsub -all "&aring;" $line "å" line
regsub -all "&auml;" $line "ä" line
regsub -all "&ouml;" $line "ö" line
regsub -all "&Aring;" $line "Å" line
regsub -all "&Auml;" $line "Ä" line
regsub -all "&Ouml;" $line "Ö" line
regsub -all "&quot;" $line {"} line
regsub -all "&#039;" $line {'} line
set ort($o) $line
incr o
}
}
close $sock


variable LastNews
if {![string equal $nyhet(1) $LastNews]} {
set LastNews "$nyhet(1)"
puthelp "PRIVMSG #hyperunknown :\002Senaste Nytt\002: '$nyhet(1)' (\002$ort(1)\002 - $datum(1)) - \037$link(1)\037"
puthelp "PRIVMSG #prim4x :\002Senaste Nytt\002: '$nyhet(1)' (\002$ort(1)\002 - $datum(1)) - \037$link(1)\037"
}
timer 1 nerikes_auto
return 1
}
