Mercurial > hg > egg-tcls
annotate fetch_feeds.tcl @ 655:4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 19 Feb 2021 19:29:51 +0200 |
parents | 5767ef9476e2 |
children | 7192d94f8c28 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/tclsh |
1 | 2 # |
3 # NOTICE! Change above path to correct tclsh binary path! | |
4 # | |
268
96310b1c88fa
feeds: Improve config resiliency.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
5 ############################################################################## |
0 | 6 # |
425
e5810c52d376
Bump some copyright years and versions.
Matti Hamalainen <ccr@tnsp.org>
parents:
424
diff
changeset
|
7 # FeedCheck fetcher v1.1 by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
578 | 8 # (C) Copyright 2008-2021 Tecnic Software productions (TNSP) |
0 | 9 # |
10 # This script is freely distributable under GNU GPL (version 2) license. | |
11 # | |
460
dbe249968591
fetch_feeds: Add support for SNI in TLS and make note about requiring tcl-tls 1.7.13+
Matti Hamalainen <ccr@tnsp.org>
parents:
425
diff
changeset
|
12 # NOTICE! NOTICE! This script REQUIRES tcl-tls 1.7.13+ if you wish to |
dbe249968591
fetch_feeds: Add support for SNI in TLS and make note about requiring tcl-tls 1.7.13+
Matti Hamalainen <ccr@tnsp.org>
parents:
425
diff
changeset
|
13 # support SSL/TLS https for URL checking. And you probably do. |
dbe249968591
fetch_feeds: Add support for SNI in TLS and make note about requiring tcl-tls 1.7.13+
Matti Hamalainen <ccr@tnsp.org>
parents:
425
diff
changeset
|
14 # |
268
96310b1c88fa
feeds: Improve config resiliency.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
15 ############################################################################## |
0 | 16 |
265
908edc54005a
feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
159
diff
changeset
|
17 ### The configuration should be in config.feeds in same directory |
908edc54005a
feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
159
diff
changeset
|
18 ### as this script. Or change the line below to point where ever |
908edc54005a
feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
159
diff
changeset
|
19 ### you wish. See "config.feeds.example" for an example config file. |
908edc54005a
feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
159
diff
changeset
|
20 source [file dirname [info script]]/config.feeds |
0 | 21 |
422
880a07485275
Add utl_ctime() to utillib and use it elsewhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
350
diff
changeset
|
22 ### Required utillib.tcl |
880a07485275
Add utl_ctime() to utillib and use it elsewhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
350
diff
changeset
|
23 source [file dirname [info script]]/utillib.tcl |
880a07485275
Add utl_ctime() to utillib and use it elsewhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
350
diff
changeset
|
24 |
0 | 25 |
268
96310b1c88fa
feeds: Improve config resiliency.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
26 ############################################################################## |
423
44c9128097cd
feeds: Remember to require sqlite3 package.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
27 package require sqlite3 |
0 | 28 package require http |
271 | 29 |
655
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
30 |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
31 ############################################################################## |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
32 ### Utility functions |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
33 |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
34 proc fetch_sanitize_encoding {uencoding} { |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
35 regsub -- "^\[a-z\]\[a-z\]_\[A-Z\]\[A-Z\]\." $uencoding "" uencoding |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
36 set uencoding [string tolower $uencoding] |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
37 regsub -- "^iso-" $uencoding "iso" uencoding |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
38 return $uencoding |
265
908edc54005a
feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
159
diff
changeset
|
39 } |
271 | 40 |
268
96310b1c88fa
feeds: Improve config resiliency.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
41 |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
42 proc fetch_dorequest { urlStr urlStatus urlSCode urlCode urlData urlMeta } { |
596 | 43 upvar $urlStatus ustatus |
44 upvar $urlSCode uscode | |
45 upvar $urlCode ucode | |
46 upvar $urlData udata | |
47 upvar $urlMeta umeta | |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
48 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
49 if {[catch {set utoken [::http::geturl $urlStr -timeout 6000 -binary 1 -headers {Accept-Encoding identity}]} uerrmsg]} { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
50 puts "HTTP request failed: $uerrmsg" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
51 return 0 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
52 } |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
53 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
54 set ustatus [::http::status $utoken] |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
55 if {$ustatus == "timeout"} { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
56 puts "HTTP request timed out ($urlStr)" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
57 return 0 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
58 } |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
59 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
60 if {$ustatus != "ok"} { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
61 puts "Error in HTTP transaction: [::http::error $utoken] ($urlStr)" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
62 return 0 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
63 } |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
64 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
65 set ustatus [::http::status $utoken] |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
66 set uscode [::http::code $utoken] |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
67 set ucode [::http::ncode $utoken] |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
68 set udata [::http::data $utoken] |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
69 array set umeta [::http::meta $utoken] |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
70 ::http::cleanup $utoken |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
71 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
72 return 1 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
73 } |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
74 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
75 |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
76 proc add_entry {uname uprefix uurl utitle} { |
142 | 77 global currclock feeds_db nitems |
292
9f90d6918626
feeds: Also use the html entity conversion from utillib here.
Matti Hamalainen <ccr@tnsp.org>
parents:
271
diff
changeset
|
78 set utmp [utl_convert_html_ent $uurl] |
147 | 79 if {[string match "http://*" $utmp] || [string match "https://*" $utmp]} { |
80 set utest "$utmp" | |
81 } else { | |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
82 if {[string range $uprefix end end] != "/" && [string range $utmp 0 0] != "/"} { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
83 set utest "$uprefix/$utmp" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
84 } else { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
85 set utest "$uprefix$utmp" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
86 } |
147 | 87 } |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
88 |
296 | 89 set usql "SELECT title FROM feeds WHERE url='[utl_escape $utest]' AND feed='[utl_escape $uname]'" |
140
b0648e05c855
Change some variable names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
90 if {![feeds_db exists $usql]} { |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
91 # puts "NEW: $utest : $utitle" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
92 set usql "INSERT INTO feeds (feed,utime,url,title) VALUES ('[utl_escape $uname]', $currclock, '[utl_escape $utest]', '[utl_escape [utl_convert_html_ent $utitle]]')" |
142 | 93 incr nitems |
140
b0648e05c855
Change some variable names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
94 if {[catch {feeds_db eval $usql} uerrmsg]} { |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
95 puts "\nError: $uerrmsg on:\n$usql" |
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
96 exit 15 |
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
97 } |
63 | 98 } |
0 | 99 } |
100 | |
101 | |
102 proc add_rss_feed {datauri dataname dataprefix} { | |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
103 if {[catch {set utoken [::http::geturl $datauri -binary 1 -timeout 6000 -headers {Accept-Encoding identity}]} uerrmsg]} { |
63 | 104 puts "Error getting $datauri: $uerrmsg" |
105 return 1 | |
106 } | |
107 set upage [::http::data $utoken] | |
108 ::http::cleanup $utoken | |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
423
diff
changeset
|
109 |
63 | 110 set umatches [regexp -all -nocase -inline -- "<item>.\*\?<title><..CDATA.(.\*\?)\\\]\\\]></title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] |
111 set nmatches [llength $umatches] | |
112 for {set n 0} {$n < $nmatches} {incr n 3} { | |
113 add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] | |
114 } | |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
423
diff
changeset
|
115 |
63 | 116 if {$nmatches == 0} { |
117 set umatches [regexp -all -nocase -inline -- "<item>.\*\?<title>(.\*\?)</title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] | |
118 set nmatches [llength $umatches] | |
119 for {set n 0} {$n < $nmatches} {incr n 3} { | |
120 add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] | |
121 } | |
122 } | |
0 | 123 |
63 | 124 if {$nmatches == 0} { |
125 set umatches [regexp -all -nocase -inline -- "<item \[^>\]*>.\*\?<title>(.\*\?)</title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] | |
126 set nmatches [llength $umatches] | |
127 for {set n 0} {$n < $nmatches} {incr n 3} { | |
128 add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] | |
129 } | |
130 } | |
143 | 131 |
63 | 132 return 0 |
0 | 133 } |
134 | |
135 | |
136 ############################################################################## | |
69
df3230f8aa46
Translate some comments to english and cosmetic fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
137 ### Fetch and parse Halla-aho's blog page data |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
138 proc fetch_halla_aho { } { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
139 set datauri "http://www.halla-aho.com/scripta/"; |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
140 set dataname "Mestari" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
141 if {![fetch_dorequest $datauri ustatus uscode ucode upage umeta]} { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
142 return 0 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
143 } |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
144 |
63 | 145 set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+\.html)\"><b>(\[^<\]+)</b>" $upage] |
146 set nmatches [llength $umatches] | |
147 for {set n 0} {$n < $nmatches} {incr n 3} { | |
148 add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] | |
149 } | |
0 | 150 |
63 | 151 set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+\.html)\">(\[^<\]\[^b\]\[^<\]+)</a>" $upage] |
152 set nmatches [llength $umatches] | |
153 for {set n 0} {$n < $nmatches} {incr n 3} { | |
154 add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] | |
155 } | |
0 | 156 } |
157 | |
158 | |
159 ### The Adventurers | |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
160 proc fetch_adventurers { } { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
161 set datauri "http://www.peldor.com/chapters/index_sidebar.html"; |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
162 set dataname "The Adventurers" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
163 if {![fetch_dorequest $datauri ustatus uscode ucode upage umeta]} { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
164 return 0 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
165 } |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
166 |
63 | 167 set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+)\">(\[^<\]+)</a>" $upage] |
168 set nmatches [llength $umatches] | |
169 for {set n 0} {$n < $nmatches} {incr n 3} { | |
170 add_entry $dataname "http://www.peldor.com/" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] | |
171 } | |
0 | 172 } |
173 | |
174 | |
175 ### Order of the Stick | |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
176 proc fetch_oots { } { |
521
4656f4fd0aa9
fetch_feeds: Fix OOTS fetching, needs https:// nowadays.
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
177 set datauri "https://www.giantitp.com/comics/oots.html"; |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
178 set dataname "OOTS" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
179 if {![fetch_dorequest $datauri ustatus uscode ucode upage umeta]} { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
180 return 0 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
181 } |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
182 |
63 | 183 set umatches [regexp -all -nocase -inline -- "<a href=\"(/comics/oots\[0-9\]+\.html)\">(\[^<\]+)</a>" $upage] |
184 set nmatches [llength $umatches] | |
185 for {set n 0} {$n < $nmatches} {incr n 3} { | |
521
4656f4fd0aa9
fetch_feeds: Fix OOTS fetching, needs https:// nowadays.
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
186 add_entry $dataname "https://www.giantitp.com" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] |
63 | 187 } |
0 | 188 } |
189 | |
190 | |
350
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
191 ### Poliisi tiedotteet |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
192 proc fetch_poliisi { datauri dataname dataprefix } { |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
193 if {![fetch_dorequest $datauri ustatus uscode ucode upage umeta]} { |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
194 return 0 |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
195 } |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
196 |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
197 set umatches [regexp -all -nocase -inline -- "<div class=\"channelitem\"><div class=\"date\">(.*?)</div><a class=\"article\" href=\"(\[^\"\]+)\">(\[^<\]+)</a>" $upage] |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
198 set nmatches [llength $umatches] |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
199 for {set n 0} {$n < $nmatches} {incr n 4} { |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
200 set stmp [string trim [lindex $umatches [expr $n+3]]] |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
201 add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] "[lindex $umatches [expr $n+1]]: $stmp" |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
202 } |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
203 } |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
204 |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
205 |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
206 |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
207 |
655
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
208 ############################################################################## |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
209 ### Open database, etc |
655
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
210 ############################################################################## |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
211 if {[info exists http_user_agent] && $http_user_agent != ""} { |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
212 ::http::config -urlencoding utf8 -useragent $http_user_agent |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
213 } else { |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
214 ::http::config -urlencoding utf8 -useragent "Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0" |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
215 } |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
216 |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
217 if {[info exists http_use_proxy] && $http_use_proxy != 0} { |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
218 ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
219 } |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
220 |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
221 if {[info exists http_tls_support] && $http_tls_support != 0} { |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
222 package require tls |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
223 ::http::register https 443 [list ::tls::socket -request true -require true -ssl2 false -ssl3 false -tls1 true -tls1.1 true -tls1.2 true -cadir $http_tls_cadir -autoservername true] |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
224 } |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
225 |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
226 |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
227 |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
228 set nitems 0 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
229 set currclock [clock seconds] |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
230 global feeds_db |
607
5767ef9476e2
Oops, Rename SQLite3 database filename configuration variable in fetch_feeds also.
Matti Hamalainen <ccr@tnsp.org>
parents:
596
diff
changeset
|
231 if {[catch {sqlite3 feeds_db $feeds_db_file} uerrmsg]} { |
5767ef9476e2
Oops, Rename SQLite3 database filename configuration variable in fetch_feeds also.
Matti Hamalainen <ccr@tnsp.org>
parents:
596
diff
changeset
|
232 puts "Could not open SQLite3 database '${feeds_db_file}': ${uerrmsg}" |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
233 exit 2 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
234 } |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
235 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
236 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
237 ### Fetch the feeds |
484
35d7be5db18b
fetch_feeds: Move the actual calling of fetching functions to the
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
238 if {[catch {feeds_fetch} uerrmsg]} { |
35d7be5db18b
fetch_feeds: Move the actual calling of fetching functions to the
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
239 puts "Error fetching feeds: $uerrmsg" |
35d7be5db18b
fetch_feeds: Move the actual calling of fetching functions to the
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
240 feeds_db close |
35d7be5db18b
fetch_feeds: Move the actual calling of fetching functions to the
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
241 exit 3 |
35d7be5db18b
fetch_feeds: Move the actual calling of fetching functions to the
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
242 } |
0 | 243 |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
244 |
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
245 ### Close database |
140
b0648e05c855
Change some variable names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
246 feeds_db close |
142 | 247 |
248 puts "$nitems new items." |