Mercurial > hg > egg-tcls
diff hae_feedit.tcl @ 63:7b03971c6d28
Remove tabs and reindent.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 08 Sep 2011 22:26:52 +0300 |
parents | bdb2b1fd6601 |
children | df3230f8aa46 |
line wrap: on
line diff
--- a/hae_feedit.tcl Thu Sep 08 22:23:33 2011 +0300 +++ b/hae_feedit.tcl Thu Sep 08 22:26:52 2011 +0300 @@ -28,57 +28,57 @@ package require http ::http::config -urlencoding iso8859-1 -useragent "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.0) Opera 9.5" if {$http_proxy != 0} { - ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port + ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port } proc convert_ent {udata} { - global html_ent - return [string map $html_ent $udata] + global html_ent + return [string map $html_ent $udata] } proc add_entry {uname uprefix uurl udesc} { - global entries isentries newurls currclock - set utest "$uprefix[convert_ent $uurl]" - set isentries($utest) 1 - if {[catch {set utmp $entries($utest)}]} { - set entries($utest) [list $currclock $uname $utest [convert_ent $udesc]] - incr newurls - } + global entries isentries newurls currclock + set utest "$uprefix[convert_ent $uurl]" + set isentries($utest) 1 + if {[catch {set utmp $entries($utest)}]} { + set entries($utest) [list $currclock $uname $utest [convert_ent $udesc]] + incr newurls + } } proc add_rss_feed {datauri dataname dataprefix} { - if {[catch {set utoken [::http::geturl $datauri -binary true -timeout 5000]} uerrmsg]} { - puts "Error getting $datauri: $uerrmsg" - return 1 - } - set upage [::http::data $utoken] - ::http::cleanup $utoken - - set umatches [regexp -all -nocase -inline -- "<item>.\*\?<title><..CDATA.(.\*\?)\\\]\\\]></title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] - set nmatches [llength $umatches] - for {set n 0} {$n < $nmatches} {incr n 3} { - add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] - } - - if {$nmatches == 0} { - set umatches [regexp -all -nocase -inline -- "<item>.\*\?<title>(.\*\?)</title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] - set nmatches [llength $umatches] - for {set n 0} {$n < $nmatches} {incr n 3} { - add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] - } - } + if {[catch {set utoken [::http::geturl $datauri -binary true -timeout 5000]} uerrmsg]} { + puts "Error getting $datauri: $uerrmsg" + return 1 + } + set upage [::http::data $utoken] + ::http::cleanup $utoken + + set umatches [regexp -all -nocase -inline -- "<item>.\*\?<title><..CDATA.(.\*\?)\\\]\\\]></title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] + set nmatches [llength $umatches] + for {set n 0} {$n < $nmatches} {incr n 3} { + add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] + } + + if {$nmatches == 0} { + set umatches [regexp -all -nocase -inline -- "<item>.\*\?<title>(.\*\?)</title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] + set nmatches [llength $umatches] + for {set n 0} {$n < $nmatches} {incr n 3} { + add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] + } + } - if {$nmatches == 0} { - set umatches [regexp -all -nocase -inline -- "<item \[^>\]*>.\*\?<title>(.\*\?)</title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] - set nmatches [llength $umatches] - for {set n 0} {$n < $nmatches} {incr n 3} { - add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] - } - } - return 0 + if {$nmatches == 0} { + set umatches [regexp -all -nocase -inline -- "<item \[^>\]*>.\*\?<title>(.\*\?)</title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] + set nmatches [llength $umatches] + for {set n 0} {$n < $nmatches} {incr n 3} { + add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] + } + } + return 0 } @@ -87,16 +87,16 @@ set oldurls 0 set newurls 0 if {![catch {set ufile [open $datafile r 0600]} uerrmsg]} { - while {![eof $ufile]} { - gets $ufile uline - set urec [split $uline "½"] - if {[llength $urec] == 4} { - set entries([lindex $urec 2]) $urec - set isentries([lindex $urec 2]) 0 - incr oldurls - } - } - close $ufile + while {![eof $ufile]} { + gets $ufile uline + set urec [split $uline "½"] + if {[llength $urec] == 4} { + set entries([lindex $urec 2]) $urec + set isentries([lindex $urec 2]) 0 + incr oldurls + } + } + close $ufile } set currclock [clock seconds] @@ -106,22 +106,22 @@ set datauri "http://www.halla-aho.com/scripta/"; set dataname "Mestari" if {[catch {set utoken [::http::geturl $datauri -binary true -timeout 5000]} uerrmsg]} { - puts "Error getting $datauri: $uerrmsg" + puts "Error getting $datauri: $uerrmsg" } else { - set upage [::http::data $utoken] - ::http::cleanup $utoken - - set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+\.html)\"><b>(\[^<\]+)</b>" $upage] - set nmatches [llength $umatches] - for {set n 0} {$n < $nmatches} {incr n 3} { - add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] - } + set upage [::http::data $utoken] + ::http::cleanup $utoken + + set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+\.html)\"><b>(\[^<\]+)</b>" $upage] + set nmatches [llength $umatches] + for {set n 0} {$n < $nmatches} {incr n 3} { + add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] + } - set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+\.html)\">(\[^<\]\[^b\]\[^<\]+)</a>" $upage] - set nmatches [llength $umatches] - for {set n 0} {$n < $nmatches} {incr n 3} { - add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] - } + set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+\.html)\">(\[^<\]\[^b\]\[^<\]+)</a>" $upage] + set nmatches [llength $umatches] + for {set n 0} {$n < $nmatches} {incr n 3} { + add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] + } } @@ -129,16 +129,16 @@ set datauri "http://www.peldor.com/chapters/index_sidebar.html"; set dataname "The Adventurers" if {[catch {set utoken [::http::geturl $datauri -binary true -timeout 5000]} uerrmsg]} { - puts "Error getting $datauri: $uerrmsg" + puts "Error getting $datauri: $uerrmsg" } else { - set upage [::http::data $utoken] - ::http::cleanup $utoken - - set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+)\">(\[^<\]+)</a>" $upage] - set nmatches [llength $umatches] - for {set n 0} {$n < $nmatches} {incr n 3} { - add_entry $dataname "http://www.peldor.com/" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] - } + set upage [::http::data $utoken] + ::http::cleanup $utoken + + set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+)\">(\[^<\]+)</a>" $upage] + set nmatches [llength $umatches] + for {set n 0} {$n < $nmatches} {incr n 3} { + add_entry $dataname "http://www.peldor.com/" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] + } } @@ -146,16 +146,16 @@ set datauri "http://www.giantitp.com/comics/oots.html"; set dataname "OOTS" if {[catch {set utoken [::http::geturl $datauri -binary true -timeout 5000]} uerrmsg]} { - puts "Error getting $datauri: $uerrmsg" + puts "Error getting $datauri: $uerrmsg" } else { - set upage [::http::data $utoken] - ::http::cleanup $utoken - - set umatches [regexp -all -nocase -inline -- "<a href=\"(/comics/oots\[0-9\]+\.html)\">(\[^<\]+)</a>" $upage] - set nmatches [llength $umatches] - for {set n 0} {$n < $nmatches} {incr n 3} { - add_entry $dataname "http://www.giantitp.com" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] - } + set upage [::http::data $utoken] + ::http::cleanup $utoken + + set umatches [regexp -all -nocase -inline -- "<a href=\"(/comics/oots\[0-9\]+\.html)\">(\[^<\]+)</a>" $upage] + set nmatches [llength $umatches] + for {set n 0} {$n < $nmatches} {incr n 3} { + add_entry $dataname "http://www.giantitp.com" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] + } } @@ -176,19 +176,19 @@ ### Avataan tulostiedosto set tmpfname "$datafile.tmp" if {[catch {set outfile [open $tmpfname w 0600]} uerrmsg]} { - puts "Error opening $tmpfname for writing: $uerrmsg" - return 1 + puts "Error opening $tmpfname for writing: $uerrmsg" + return 1 } set uexpire [expr [clock seconds] - (7*24*60*60)] foreach {ukey udata} [array get entries] { -# if {$isentries($ukey) != 0 || [lindex $udata 0] >= $uexpire} { - puts $outfile [join $udata "½"] -# } +# if {$isentries($ukey) != 0 || [lindex $udata 0] >= $uexpire} { + puts $outfile [join $udata "½"] +# } } close $outfile if {[catch {file rename -force -- $tmpfname $datafile} uerrmsg]} { - puts "Error renaming $tmpfname to $datafile: $uerrmsg" + puts "Error renaming $tmpfname to $datafile: $uerrmsg" } #puts "$newurls new entries."