Mercurial > hg > egg-tcls
annotate fetch_feeds.tcl @ 698:6ba9f961e463 default tip
quotedb: Bump version and copyright.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 18 Sep 2023 11:38:41 +0300 |
parents | 721c8cef5039 |
children |
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 } { |
660
ab2ba0b82407
fetch_feeds: Use the common HTTP helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
43 |
596 | 44 upvar $urlStatus ustatus |
45 upvar $urlSCode uscode | |
46 upvar $urlCode ucode | |
47 upvar $urlData udata | |
48 upvar $urlMeta umeta | |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
49 |
656
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
50 set urlHeaders {} |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
51 lappend urlHeaders "Accept-Encoding" "identity" |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
52 #lappend urlHeaders "Connection" "keep-alive" |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
53 |
660
ab2ba0b82407
fetch_feeds: Use the common HTTP helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
54 set uresult [utl_http_do_request $urlHeaders $urlStr ustatus uscode ucode udata umeta] |
ab2ba0b82407
fetch_feeds: Use the common HTTP helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
55 if {$uresult == -1} { |
ab2ba0b82407
fetch_feeds: Use the common HTTP helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
56 puts "HTTP request failed: $uscode ($urlStr)" |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
57 return 0 |
660
ab2ba0b82407
fetch_feeds: Use the common HTTP helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
58 } elseif {$uresult < 0} { |
ab2ba0b82407
fetch_feeds: Use the common HTTP helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
59 urllog_log "Error in HTTP request: $ustatus / $uscode ($urlStr)" |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
60 return 0 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
61 } |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
62 |
656
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
63 ### Perform encoding conversion if necessary |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
64 if {$ucode >= 200 && $ucode <= 205} { |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
65 set uenc_doc "" |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
66 set uenc_http "" |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
67 set uencoding "" |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
68 |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
69 if {[info exists umeta(content-type)] && [regexp -nocase {charset\s*=\s*([a-z0-9._-]+)} $umeta(content-type) -> uenc_http]} { |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
70 # Found character set encoding information in HTTP headers |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
71 } |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
72 |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
73 if {[regexp -nocase -- "<meta.\*\?content=\"text/html.\*\?charset=(\[^\"\]*)\".\*\?/\?>" $udata -> uenc_doc]} { |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
74 # Found old style HTML meta tag with character set information |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
75 } elseif {[regexp -nocase -- "<meta.\*\?charset=\"(\[^\"\]*)\".\*\?/\?>" $udata -> uenc_doc]} { |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
76 # Found HTML5 style meta tag with character set information |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
77 } |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
78 |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
79 # Make sanitized versions of the encoding strings |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
80 set uenc_http2 [fetch_sanitize_encoding $uenc_http] |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
81 set uenc_doc2 [fetch_sanitize_encoding $uenc_doc] |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
82 |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
83 # Check if the document has specified encoding |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
84 set uencoding $uenc_http2 |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
85 if {$uencoding == "" && $uenc_doc2 != ""} { |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
86 set uencoding $uenc_doc2 |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
87 } elseif {$uencoding == ""} { |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
88 # If _NO_ known encoding of any kind, assume the default of iso8859-1 |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
89 set uencoding "iso8859-1" |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
90 } |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
91 |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
92 #puts "Charsets: http='$uenc_http', doc='$uenc_doc' / sanitized http='$uenc_http2', doc='$uenc_doc2' -> '$uencoding'" |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
93 |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
94 # Get the document title, if any |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
95 if {$uencoding != ""} { |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
96 if {[catch {set udata [encoding convertfrom $uencoding $udata]} cerrmsg]} { |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
97 puts "Error in charset conversion: $urlStr: $cerrmsg" |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
98 return 0 |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
99 } |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
100 } |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
101 return 1 |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
102 } else { |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
103 return 0 |
7192d94f8c28
fetch_feeds: Copy improved HTTP request code from urllog script.
Matti Hamalainen <ccr@tnsp.org>
parents:
655
diff
changeset
|
104 } |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
105 } |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
106 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
107 |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
108 proc add_entry {uname uprefix uurl utitle} { |
142 | 109 global currclock feeds_db nitems |
657
f46c152183a2
fetch_feeds: Use generic HTTP request handling code also for RSS feed fetches.
Matti Hamalainen <ccr@tnsp.org>
parents:
656
diff
changeset
|
110 |
292
9f90d6918626
feeds: Also use the html entity conversion from utillib here.
Matti Hamalainen <ccr@tnsp.org>
parents:
271
diff
changeset
|
111 set utmp [utl_convert_html_ent $uurl] |
147 | 112 if {[string match "http://*" $utmp] || [string match "https://*" $utmp]} { |
113 set utest "$utmp" | |
114 } else { | |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
115 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
|
116 set utest "$uprefix/$utmp" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
117 } else { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
118 set utest "$uprefix$utmp" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
119 } |
147 | 120 } |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
121 |
296 | 122 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
|
123 if {![feeds_db exists $usql]} { |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
124 # puts "NEW: $utest : $utitle" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
125 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 | 126 incr nitems |
140
b0648e05c855
Change some variable names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
127 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
|
128 puts "\nError: $uerrmsg on:\n$usql" |
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
129 exit 15 |
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
130 } |
63 | 131 } |
0 | 132 } |
133 | |
134 | |
135 proc add_rss_feed {datauri dataname dataprefix} { | |
657
f46c152183a2
fetch_feeds: Use generic HTTP request handling code also for RSS feed fetches.
Matti Hamalainen <ccr@tnsp.org>
parents:
656
diff
changeset
|
136 if {![fetch_dorequest $datauri ustatus uscode ucode upage umeta]} { |
f46c152183a2
fetch_feeds: Use generic HTTP request handling code also for RSS feed fetches.
Matti Hamalainen <ccr@tnsp.org>
parents:
656
diff
changeset
|
137 return 0 |
63 | 138 } |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
423
diff
changeset
|
139 |
63 | 140 set umatches [regexp -all -nocase -inline -- "<item>.\*\?<title><..CDATA.(.\*\?)\\\]\\\]></title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] |
141 set nmatches [llength $umatches] | |
142 for {set n 0} {$n < $nmatches} {incr n 3} { | |
143 add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] | |
144 } | |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
423
diff
changeset
|
145 |
63 | 146 if {$nmatches == 0} { |
147 set umatches [regexp -all -nocase -inline -- "<item>.\*\?<title>(.\*\?)</title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] | |
148 set nmatches [llength $umatches] | |
149 for {set n 0} {$n < $nmatches} {incr n 3} { | |
150 add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] | |
151 } | |
152 } | |
0 | 153 |
63 | 154 if {$nmatches == 0} { |
155 set umatches [regexp -all -nocase -inline -- "<item \[^>\]*>.\*\?<title>(.\*\?)</title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] | |
156 set nmatches [llength $umatches] | |
157 for {set n 0} {$n < $nmatches} {incr n 3} { | |
158 add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] | |
159 } | |
160 } | |
143 | 161 |
63 | 162 return 0 |
0 | 163 } |
164 | |
165 | |
166 ############################################################################## | |
69
df3230f8aa46
Translate some comments to english and cosmetic fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
167 ### 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
|
168 proc fetch_halla_aho { } { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
169 set datauri "http://www.halla-aho.com/scripta/"; |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
170 set dataname "Mestari" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
171 if {![fetch_dorequest $datauri ustatus uscode ucode upage umeta]} { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
172 return 0 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
173 } |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
174 |
63 | 175 set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+\.html)\"><b>(\[^<\]+)</b>" $upage] |
176 set nmatches [llength $umatches] | |
177 for {set n 0} {$n < $nmatches} {incr n 3} { | |
178 add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] | |
179 } | |
0 | 180 |
63 | 181 set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+\.html)\">(\[^<\]\[^b\]\[^<\]+)</a>" $upage] |
182 set nmatches [llength $umatches] | |
183 for {set n 0} {$n < $nmatches} {incr n 3} { | |
184 add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] | |
185 } | |
0 | 186 } |
187 | |
188 | |
189 ### The Adventurers | |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
190 proc fetch_adventurers { } { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
191 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
|
192 set dataname "The Adventurers" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
193 if {![fetch_dorequest $datauri ustatus uscode ucode upage umeta]} { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
194 return 0 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
195 } |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
196 |
63 | 197 set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+)\">(\[^<\]+)</a>" $upage] |
198 set nmatches [llength $umatches] | |
199 for {set n 0} {$n < $nmatches} {incr n 3} { | |
200 add_entry $dataname "http://www.peldor.com/" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] | |
201 } | |
0 | 202 } |
203 | |
204 | |
205 ### Order of the Stick | |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
206 proc fetch_oots { } { |
521
4656f4fd0aa9
fetch_feeds: Fix OOTS fetching, needs https:// nowadays.
Matti Hamalainen <ccr@tnsp.org>
parents:
484
diff
changeset
|
207 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
|
208 set dataname "OOTS" |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
209 if {![fetch_dorequest $datauri ustatus uscode ucode upage umeta]} { |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
210 return 0 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
211 } |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
212 |
63 | 213 set umatches [regexp -all -nocase -inline -- "<a href=\"(/comics/oots\[0-9\]+\.html)\">(\[^<\]+)</a>" $upage] |
214 set nmatches [llength $umatches] | |
215 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
|
216 add_entry $dataname "https://www.giantitp.com" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] |
63 | 217 } |
0 | 218 } |
219 | |
220 | |
350
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
221 ### Poliisi tiedotteet |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
222 proc fetch_poliisi { datauri dataname dataprefix } { |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
223 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
|
224 return 0 |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
225 } |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
226 |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
227 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
|
228 set nmatches [llength $umatches] |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 } |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
233 } |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
234 |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
235 |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
236 |
51c08336d7b1
feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents:
323
diff
changeset
|
237 |
655
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
238 ############################################################################## |
661
721c8cef5039
fetch_feeds: Clean up some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
239 ### |
721c8cef5039
fetch_feeds: Clean up some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
240 ### Main code starts |
721c8cef5039
fetch_feeds: Clean up some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
241 ### |
655
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
242 ############################################################################## |
661
721c8cef5039
fetch_feeds: Clean up some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
243 ### Set up HTTP stuff |
655
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
244 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
|
245 ::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
|
246 } else { |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
247 ::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
|
248 } |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
249 |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
250 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
|
251 ::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
|
252 } |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
253 |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
254 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
|
255 package require tls |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
256 ::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
|
257 } |
4b985abf5aba
fetch_feeds: Move HTTP initialization to end of script.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
258 |
661
721c8cef5039
fetch_feeds: Clean up some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
660
diff
changeset
|
259 ### Open database |
321
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
260 set nitems 0 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
261 set currclock [clock seconds] |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
262 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
|
263 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
|
264 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
|
265 exit 2 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
266 } |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
267 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
268 |
d8b957796121
feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
269 ### 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
|
270 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
|
271 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
|
272 feeds_db close |
35d7be5db18b
fetch_feeds: Move the actual calling of fetching functions to the
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
273 exit 3 |
35d7be5db18b
fetch_feeds: Move the actual calling of fetching functions to the
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
274 } |
0 | 275 |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
276 |
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
277 ### Close database |
140
b0648e05c855
Change some variable names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
278 feeds_db close |
142 | 279 |
280 puts "$nitems new items." |