annotate fetch_feeds.tcl @ 415:ff932030a9b3

weather: Bump version.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 07 Jan 2017 22:41:07 +0200
parents 51c08336d7b1
children 880a07485275
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 #
323
9380535b8f12 feeds: Bump version.
Matti Hamalainen <ccr@tnsp.org>
parents: 322
diff changeset
7 # FeedCheck fetcher v1.0 by Matti 'ccr' Hamalainen <ccr@tnsp.org>
265
908edc54005a feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 159
diff changeset
8 # (C) Copyright 2008-2015 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 #
268
96310b1c88fa feeds: Improve config resiliency.
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
12 ##############################################################################
139
3305e142eecc Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
13 package require sqlite3
265
908edc54005a feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 159
diff changeset
14 source [file dirname [info script]]/utillib.tcl
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
265
908edc54005a feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 159
diff changeset
16 ### 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
17 ### 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
18 ### 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
19 source [file dirname [info script]]/config.feeds
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
268
96310b1c88fa feeds: Improve config resiliency.
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
22 ##############################################################################
139
3305e142eecc Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
23
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 package require http
271
f47b41d2be64 feeds: Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
25
265
908edc54005a feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 159
diff changeset
26 if {[info exists http_user_agent] && $http_user_agent != ""} {
296
a7455b0dc144 Fix feed fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 292
diff changeset
27 ::http::config -urlencoding utf8 -useragent $http_user_agent
265
908edc54005a feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 159
diff changeset
28 } else {
322
b4adc56446f6 feeds: Update user agent.
Matti Hamalainen <ccr@tnsp.org>
parents: 321
diff changeset
29 ::http::config -urlencoding utf8 -useragent "Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0"
265
908edc54005a feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 159
diff changeset
30 }
271
f47b41d2be64 feeds: Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
31
268
96310b1c88fa feeds: Improve config resiliency.
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
32 if {[info exists http_use_proxy] && $http_use_proxy != 0} {
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
33 ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
268
96310b1c88fa feeds: Improve config resiliency.
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
36 if {[info exists http_tls_support] && $http_tls_support != 0} {
265
908edc54005a feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 159
diff changeset
37 package require tls
908edc54005a feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 159
diff changeset
38 ::http::register https 443 [list ::tls::socket -request 1 -require 1 -tls1 1 -cadir $http_tls_cadir]
908edc54005a feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 159
diff changeset
39 }
908edc54005a feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 159
diff changeset
40
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
268
96310b1c88fa feeds: Improve config resiliency.
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
42 ##############################################################################
96310b1c88fa feeds: Improve config resiliency.
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
43
321
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
44 proc fetch_dorequest { urlStr urlStatus urlSCode urlCode urlData urlMeta } {
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
45 upvar 1 $urlStatus ustatus
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
46 upvar 1 $urlSCode uscode
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
47 upvar 1 $urlCode ucode
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
48 upvar 1 $urlData udata
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
49 upvar 1 $urlMeta umeta
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
50
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
51 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
52 puts "HTTP request failed: $uerrmsg"
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
53 return 0
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
54 }
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
55
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
56 set ustatus [::http::status $utoken]
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
57 if {$ustatus == "timeout"} {
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
58 puts "HTTP request timed out ($urlStr)"
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
59 return 0
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
60 }
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 if {$ustatus != "ok"} {
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
63 puts "Error in HTTP transaction: [::http::error $utoken] ($urlStr)"
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
64 return 0
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
65 }
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
66
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
67 set ustatus [::http::status $utoken]
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
68 set uscode [::http::code $utoken]
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
69 set ucode [::http::ncode $utoken]
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
70 set udata [::http::data $utoken]
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
71 array set umeta [::http::meta $utoken]
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
72 ::http::cleanup $utoken
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 return 1
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
75 }
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
76
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
77
139
3305e142eecc Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
78 proc add_entry {uname uprefix uurl utitle} {
142
4c51eeba993f Rename table.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
79 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
80 set utmp [utl_convert_html_ent $uurl]
147
48460e925a8c Fix feed getter.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
81 if {[string match "http://*" $utmp] || [string match "https://*" $utmp]} {
48460e925a8c Fix feed getter.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
82 set utest "$utmp"
48460e925a8c Fix feed getter.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
83 } else {
321
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
84 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
85 set utest "$uprefix/$utmp"
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
86 } else {
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
87 set utest "$uprefix$utmp"
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
88 }
147
48460e925a8c Fix feed getter.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
89 }
139
3305e142eecc Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
90
296
a7455b0dc144 Fix feed fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 292
diff changeset
91 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
92 if {![feeds_db exists $usql]} {
321
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
93 # puts "NEW: $utest : $utitle"
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
94 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
95 incr nitems
140
b0648e05c855 Change some variable names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
96 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
97 puts "\nError: $uerrmsg on:\n$usql"
3305e142eecc Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
98 exit 15
3305e142eecc Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
99 }
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
100 }
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 proc add_rss_feed {datauri dataname dataprefix} {
321
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
105 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
106 puts "Error getting $datauri: $uerrmsg"
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
107 return 1
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
108 }
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
109 set upage [::http::data $utoken]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
110 ::http::cleanup $utoken
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
111
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
112 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
113 set nmatches [llength $umatches]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
114 for {set n 0} {$n < $nmatches} {incr n 3} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
115 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
116 }
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
117
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
118 if {$nmatches == 0} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
119 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
120 set nmatches [llength $umatches]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
121 for {set n 0} {$n < $nmatches} {incr n 3} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
122 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
123 }
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
124 }
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
126 if {$nmatches == 0} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
127 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
128 set nmatches [llength $umatches]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
129 for {set n 0} {$n < $nmatches} {incr n 3} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
130 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
131 }
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
132 }
143
96b42289f1e7 Fixes in feeds checker.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
133
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
134 return 0
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 ##############################################################################
69
df3230f8aa46 Translate some comments to english and cosmetic fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
139 ### 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
140 proc fetch_halla_aho { } {
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
141 set datauri "http://www.halla-aho.com/scripta/";
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
142 set dataname "Mestari"
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
143 if {![fetch_dorequest $datauri ustatus uscode ucode upage umeta]} {
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
144 return 0
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
145 }
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
146
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
147 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
148 set nmatches [llength $umatches]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
149 for {set n 0} {$n < $nmatches} {incr n 3} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
150 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
151 }
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
153 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
154 set nmatches [llength $umatches]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
155 for {set n 0} {$n < $nmatches} {incr n 3} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
156 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
157 }
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 ### The Adventurers
321
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
162 proc fetch_adventurers { } {
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
163 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
164 set dataname "The Adventurers"
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
165 if {![fetch_dorequest $datauri ustatus uscode ucode upage umeta]} {
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
166 return 0
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
167 }
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
168
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
169 set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+)\">(\[^<\]+)</a>" $upage]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
170 set nmatches [llength $umatches]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
171 for {set n 0} {$n < $nmatches} {incr n 3} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
172 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
173 }
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 ### Order of the Stick
321
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
178 proc fetch_oots { } {
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
179 set datauri "http://www.giantitp.com/comics/oots.html";
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
180 set dataname "OOTS"
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
181 if {![fetch_dorequest $datauri ustatus uscode ucode upage umeta]} {
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
182 return 0
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
183 }
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
184
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
185 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
186 set nmatches [llength $umatches]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
187 for {set n 0} {$n < $nmatches} {incr n 3} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
188 add_entry $dataname "http://www.giantitp.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
189 }
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
350
51c08336d7b1 feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents: 323
diff changeset
193 ### Poliisi tiedotteet
51c08336d7b1 feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents: 323
diff changeset
194 proc fetch_poliisi { datauri dataname dataprefix } {
51c08336d7b1 feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents: 323
diff changeset
195 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
196 return 0
51c08336d7b1 feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents: 323
diff changeset
197 }
51c08336d7b1 feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents: 323
diff changeset
198
51c08336d7b1 feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents: 323
diff changeset
199 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
200 set nmatches [llength $umatches]
51c08336d7b1 feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents: 323
diff changeset
201 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
202 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
203 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
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
51c08336d7b1 feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents: 323
diff changeset
208
51c08336d7b1 feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents: 323
diff changeset
209
321
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
210 ### Open database, etc
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
211 set nitems 0
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
212 set currclock [clock seconds]
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
213 global feeds_db
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
214 if {[catch {sqlite3 feeds_db $feeds_dbfile} uerrmsg]} {
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
215 puts "Could not open SQLite3 database '$feeds_dbfile': $uerrmsg."
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
216 exit 2
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
217 }
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
218
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
219
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
220 ### Fetch the feeds
350
51c08336d7b1 feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents: 323
diff changeset
221 fetch_poliisi "http://www.poliisi.fi/oulu/tiedotteet/1/0?all1/0" "Poliisi/Oulu" "http://www.poliisi.fi"
51c08336d7b1 feeds: Add support for Poliisi.fi information reports.
Matti Hamalainen <ccr@tnsp.org>
parents: 323
diff changeset
222
321
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
223 fetch_halla_aho
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
224
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
225 fetch_adventurers
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
226
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
227 fetch_oots
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
228
143
96b42289f1e7 Fixes in feeds checker.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
229 #add_rss_feed "http://www.kaleva.fi/rss/145.xml" "Kaleva/Tiede" ""
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 add_rss_feed "http://www.effi.org/xml/uutiset.rss" "EFFI" ""
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
143
96b42289f1e7 Fixes in feeds checker.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
233 add_rss_feed "http://static.mtv3.fi/rss/uutiset_rikos.rss" "MTV3/Rikos" ""
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234
321
d8b957796121 feeds: Refactor the feeds fetching.
Matti Hamalainen <ccr@tnsp.org>
parents: 296
diff changeset
235 #add_rss_feed "http://www.blastwave-comic.com/rss/blastwave.xml" "Blastwave" ""
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 #add_rss_feed "http://lehti.samizdat.info/feed/" "Lehti" ""
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238
139
3305e142eecc Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
239
3305e142eecc Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
240 ### Close database
140
b0648e05c855 Change some variable names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
241 feeds_db close
142
4c51eeba993f Rename table.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
242
4c51eeba993f Rename table.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
243 puts "$nitems new items."