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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #!/usr/bin/tclsh
1
bdb2b1fd6601 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
2 #
bdb2b1fd6601 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
3 # NOTICE! Change above path to correct tclsh binary path!
bdb2b1fd6601 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
4 #
268
96310b1c88fa feeds: Improve config resiliency.
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
5 ##############################################################################
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
14dfb925a64a Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
8 # (C) Copyright 2008-2021 Tecnic Software productions (TNSP)
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 # This script is freely distributable under GNU GPL (version 2) license.
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 package require http
271
f47b41d2be64 feeds: Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
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
f47b41d2be64 feeds: Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
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
b524a6e4be63 feeds: Slight cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 578
diff changeset
43 upvar $urlStatus ustatus
b524a6e4be63 feeds: Slight cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 578
diff changeset
44 upvar $urlSCode uscode
b524a6e4be63 feeds: Slight cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 578
diff changeset
45 upvar $urlCode ucode
b524a6e4be63 feeds: Slight cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 578
diff changeset
46 upvar $urlData udata
b524a6e4be63 feeds: Slight cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 578
diff changeset
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
4c51eeba993f Rename table.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
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
48460e925a8c Fix feed getter.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
79 if {[string match "http://*" $utmp] || [string match "https://*" $utmp]} {
48460e925a8c Fix feed getter.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
80 set utest "$utmp"
48460e925a8c Fix feed getter.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
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
48460e925a8c Fix feed getter.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
87 }
139
3305e142eecc Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
88
296
a7455b0dc144 Fix feed fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 292
diff changeset
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
4c51eeba993f Rename table.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
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
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
98 }
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
104 puts "Error getting $datauri: $uerrmsg"
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
105 return 1
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
106 }
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
107 set upage [::http::data $utoken]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
108 ::http::cleanup $utoken
424
825cac46b1cb Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 423
diff changeset
109
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
110 set umatches [regexp -all -nocase -inline -- "<item>.\*\?<title><..CDATA.(.\*\?)\\\]\\\]></title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
111 set nmatches [llength $umatches]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
112 for {set n 0} {$n < $nmatches} {incr n 3} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
113 add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
114 }
424
825cac46b1cb Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 423
diff changeset
115
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
116 if {$nmatches == 0} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
117 set umatches [regexp -all -nocase -inline -- "<item>.\*\?<title>(.\*\?)</title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
118 set nmatches [llength $umatches]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
119 for {set n 0} {$n < $nmatches} {incr n 3} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
120 add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
121 }
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
122 }
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
124 if {$nmatches == 0} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
125 set umatches [regexp -all -nocase -inline -- "<item \[^>\]*>.\*\?<title>(.\*\?)</title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
126 set nmatches [llength $umatches]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
127 for {set n 0} {$n < $nmatches} {incr n 3} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
128 add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
129 }
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
130 }
143
96b42289f1e7 Fixes in feeds checker.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
131
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
132 return 0
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
145 set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+\.html)\"><b>(\[^<\]+)</b>" $upage]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
146 set nmatches [llength $umatches]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
147 for {set n 0} {$n < $nmatches} {incr n 3} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
148 add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
149 }
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
151 set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+\.html)\">(\[^<\]\[^b\]\[^<\]+)</a>" $upage]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
152 set nmatches [llength $umatches]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
153 for {set n 0} {$n < $nmatches} {incr n 3} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
154 add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
155 }
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
167 set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+)\">(\[^<\]+)</a>" $upage]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
168 set nmatches [llength $umatches]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
169 for {set n 0} {$n < $nmatches} {incr n 3} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
170 add_entry $dataname "http://www.peldor.com/" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
171 }
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
183 set umatches [regexp -all -nocase -inline -- "<a href=\"(/comics/oots\[0-9\]+\.html)\">(\[^<\]+)</a>" $upage]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
184 set nmatches [llength $umatches]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
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
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
187 }
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
4c51eeba993f Rename table.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
247
4c51eeba993f Rename table.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
248 puts "$nitems new items."