Mercurial > hg > egg-tcls
annotate get_feeds.tcl @ 145:c94b4e1a2ed4
Rename some files, etc.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 05 Jun 2013 15:51:30 +0300 |
parents | hae_feedit.tcl@96b42289f1e7 |
children | 7106dd8db4de |
rev | line source |
---|---|
0 | 1 #!/usr/bin/tclsh |
1 | 2 # |
3 # NOTICE! Change above path to correct tclsh binary path! | |
4 # | |
69
df3230f8aa46
Translate some comments to english and cosmetic fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
5 ########################################################################## |
0 | 6 # |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
7 # FeedCheck fetcher v0.8 by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
8 # (C) Copyright 2008-2013 Tecnic Software productions (TNSP) |
0 | 9 # |
10 # This script is freely distributable under GNU GPL (version 2) license. | |
11 # | |
69
df3230f8aa46
Translate some comments to english and cosmetic fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
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 |
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
14 source [file dirname [info script]]/util_convert.tcl |
0 | 15 |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
16 # SQLite3 database, MUST be set to same as in feeds.tcl |
140
b0648e05c855
Change some variable names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
17 set feeds_dbfile "/home/niinuska/bot/feeds.sqlite" |
0 | 18 |
19 # Use a HTTP proxy? 1 = yes, 0 = no | |
20 set http_proxy 0 | |
21 | |
22 # HTTP proxy address and port | |
23 set http_proxy_host "cache.inet.fi" | |
24 set http_proxy_port 800 | |
25 | |
26 | |
69
df3230f8aa46
Translate some comments to english and cosmetic fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
27 ########################################################################## |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
28 |
0 | 29 set html_ent [split " | |»|>>|"|\"|ä|ä|ö|ö|Ä|Ä|Ö|Ö|&|&|<|<|>|>|ä|ä|ö|ö|Ä|Ä" "|"] |
30 | |
31 package require http | |
32 ::http::config -urlencoding iso8859-1 -useragent "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.0) Opera 9.5" | |
33 if {$http_proxy != 0} { | |
63 | 34 ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port |
0 | 35 } |
36 | |
37 | |
38 proc convert_ent {udata} { | |
63 | 39 global html_ent |
40 return [string map $html_ent $udata] | |
0 | 41 } |
42 | |
43 | |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
44 proc add_entry {uname uprefix uurl utitle} { |
142 | 45 global currclock feeds_db nitems |
63 | 46 set utest "$uprefix[convert_ent $uurl]" |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
47 |
142 | 48 set usql "SELECT title FROM feeds WHERE url='[escape $utest]' AND feed='[escape $uname]'" |
140
b0648e05c855
Change some variable names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
49 if {![feeds_db exists $usql]} { |
142 | 50 set usql "INSERT INTO feeds (feed,utime,url,title) VALUES ('[escape $uname]', $currclock, '[escape $utest]', '[escape $utitle]')" |
51 incr nitems | |
140
b0648e05c855
Change some variable names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
52 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
|
53 puts "\nError: $uerrmsg on:\n$usql" |
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
54 exit 15 |
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
55 } |
63 | 56 } |
0 | 57 } |
58 | |
59 | |
60 proc add_rss_feed {datauri dataname dataprefix} { | |
63 | 61 if {[catch {set utoken [::http::geturl $datauri -binary true -timeout 5000]} uerrmsg]} { |
62 puts "Error getting $datauri: $uerrmsg" | |
63 return 1 | |
64 } | |
65 set upage [::http::data $utoken] | |
66 ::http::cleanup $utoken | |
67 | |
68 set umatches [regexp -all -nocase -inline -- "<item>.\*\?<title><..CDATA.(.\*\?)\\\]\\\]></title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] | |
69 set nmatches [llength $umatches] | |
70 for {set n 0} {$n < $nmatches} {incr n 3} { | |
71 add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] | |
72 } | |
73 | |
74 if {$nmatches == 0} { | |
75 set umatches [regexp -all -nocase -inline -- "<item>.\*\?<title>(.\*\?)</title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] | |
76 set nmatches [llength $umatches] | |
77 for {set n 0} {$n < $nmatches} {incr n 3} { | |
78 add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] | |
79 } | |
80 } | |
0 | 81 |
63 | 82 if {$nmatches == 0} { |
83 set umatches [regexp -all -nocase -inline -- "<item \[^>\]*>.\*\?<title>(.\*\?)</title>.\*\?<link>(http.\*\?)</link>.\*\?</item>" $upage] | |
84 set nmatches [llength $umatches] | |
85 for {set n 0} {$n < $nmatches} {incr n 3} { | |
86 add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] | |
87 } | |
88 } | |
143 | 89 |
63 | 90 return 0 |
0 | 91 } |
92 | |
93 | |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
94 ### Open database, etc |
142 | 95 set nitems 0 |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
96 set currclock [clock seconds] |
140
b0648e05c855
Change some variable names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
97 global feeds_db |
b0648e05c855
Change some variable names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
98 if {[catch {sqlite3 feeds_db $feeds_dbfile} uerrmsg]} { |
b0648e05c855
Change some variable names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
99 puts "Could not open SQLite3 database '$feeds_dbfile': $uerrmsg." |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
100 exit 2 |
0 | 101 } |
102 | |
103 | |
104 ############################################################################## | |
69
df3230f8aa46
Translate some comments to english and cosmetic fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
105 ### Fetch and parse Halla-aho's blog page data |
0 | 106 set datauri "http://www.halla-aho.com/scripta/"; |
107 set dataname "Mestari" | |
108 if {[catch {set utoken [::http::geturl $datauri -binary true -timeout 5000]} uerrmsg]} { | |
63 | 109 puts "Error getting $datauri: $uerrmsg" |
0 | 110 } else { |
63 | 111 set upage [::http::data $utoken] |
112 ::http::cleanup $utoken | |
113 | |
114 set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+\.html)\"><b>(\[^<\]+)</b>" $upage] | |
115 set nmatches [llength $umatches] | |
116 for {set n 0} {$n < $nmatches} {incr n 3} { | |
117 add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] | |
118 } | |
0 | 119 |
63 | 120 set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+\.html)\">(\[^<\]\[^b\]\[^<\]+)</a>" $upage] |
121 set nmatches [llength $umatches] | |
122 for {set n 0} {$n < $nmatches} {incr n 3} { | |
123 add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] | |
124 } | |
0 | 125 } |
126 | |
127 | |
128 ### The Adventurers | |
129 set datauri "http://www.peldor.com/chapters/index_sidebar.html"; | |
130 set dataname "The Adventurers" | |
131 if {[catch {set utoken [::http::geturl $datauri -binary true -timeout 5000]} uerrmsg]} { | |
63 | 132 puts "Error getting $datauri: $uerrmsg" |
0 | 133 } else { |
63 | 134 set upage [::http::data $utoken] |
135 ::http::cleanup $utoken | |
136 | |
137 set umatches [regexp -all -nocase -inline -- "<a href=\"(\[^\"\]+)\">(\[^<\]+)</a>" $upage] | |
138 set nmatches [llength $umatches] | |
139 for {set n 0} {$n < $nmatches} {incr n 3} { | |
140 add_entry $dataname "http://www.peldor.com/" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] | |
141 } | |
0 | 142 } |
143 | |
144 | |
145 ### Order of the Stick | |
146 set datauri "http://www.giantitp.com/comics/oots.html"; | |
147 set dataname "OOTS" | |
148 if {[catch {set utoken [::http::geturl $datauri -binary true -timeout 5000]} uerrmsg]} { | |
63 | 149 puts "Error getting $datauri: $uerrmsg" |
0 | 150 } else { |
63 | 151 set upage [::http::data $utoken] |
152 ::http::cleanup $utoken | |
153 | |
154 set umatches [regexp -all -nocase -inline -- "<a href=\"(/comics/oots\[0-9\]+\.html)\">(\[^<\]+)</a>" $upage] | |
155 set nmatches [llength $umatches] | |
156 for {set n 0} {$n < $nmatches} {incr n 3} { | |
157 add_entry $dataname "http://www.giantitp.com" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] | |
158 } | |
0 | 159 } |
160 | |
161 | |
69
df3230f8aa46
Translate some comments to english and cosmetic fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
162 ### Generic RSS-feed fetching |
143 | 163 #add_rss_feed "http://www.kaleva.fi/rss/145.xml" "Kaleva/Tiede" "" |
0 | 164 |
165 add_rss_feed "http://www.effi.org/xml/uutiset.rss" "EFFI" "" | |
166 | |
143 | 167 add_rss_feed "http://static.mtv3.fi/rss/uutiset_rikos.rss" "MTV3/Rikos" "" |
0 | 168 |
169 add_rss_feed "http://www.blastwave-comic.com/rss/blastwave.xml" "Blastwave" "" | |
170 | |
171 #add_rss_feed "http://lehti.samizdat.info/feed/" "Lehti" "" | |
172 | |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
173 |
0 | 174 |
139
3305e142eecc
Change feed fetcher to use SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
175 ### Close database |
140
b0648e05c855
Change some variable names, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
176 feeds_db close |
142 | 177 |
178 puts "$nitems new items." |