Mercurial > hg > egg-tcls
annotate feeds.tcl @ 226:0ff78e418e77
feeds: Don't add # to channel names automatically.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 01 Dec 2014 11:30:44 +0200 |
parents | 7a549487fba3 |
children | 908edc54005a |
rev | line source |
---|---|
70 | 1 ########################################################################## |
0 | 2 # |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
3 # FeedCheck v0.8 by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
4 # (C) Copyright 2008-2013 Tecnic Software productions (TNSP) |
0 | 5 # |
6 # Requires get_feeds.tcl to be run as a cronjob, for example | |
7 # 15 * * * * /absolute/path/to/get_feeds.tcl | |
8 # | |
145 | 9 # See also create_feeds_db.tcl OR convert_feeds_db.tcl, as you will |
10 # need to either create a SQLite3 database or convert old text flat | |
11 # file to SQLite3. | |
12 # | |
0 | 13 # This script is freely distributable under GNU GPL (version 2) license. |
14 # | |
70 | 15 ########################################################################## |
0 | 16 |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
17 # SQLite3 database, MUST be set to same as in feeds.tcl |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
18 set feeds_dbfile "/home/niinuska/bot/feeds.sqlite" |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
19 |
144 | 20 # How often to check for newly added feed items from the database? |
21 # (in minutes) This has nothing to do how often the backend script | |
22 # is run and actually scans / pulls the feeds, that is done in CRON. | |
23 # See get_feeds.tcl for more information. | |
24 set feeds_check_period 5 | |
0 | 25 |
26 # Set channels and feed filters here: | |
226
0ff78e418e77
feeds: Don't add # to channel names automatically.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
27 # "#channel" "feedname|feedname2" |
0 | 28 # feednames can use matching, e.g. "mtv3*" would match all beginning with "mtv3" |
29 array set feeds_channels { | |
226
0ff78e418e77
feeds: Don't add # to channel names automatically.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
30 "#mazmlame" "the adventurers|oots|mestari|blastwave" |
0ff78e418e77
feeds: Don't add # to channel names automatically.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
31 "#fireball" "mestari" |
0ff78e418e77
feeds: Don't add # to channel names automatically.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
32 "#tnsp" "the adventurers|oots|mestari" |
0 | 33 } |
34 | |
35 | |
36 set feeds_preferredmsg "PRIVMSG" | |
37 | |
38 | |
70 | 39 ########################################################################## |
0 | 40 # No need to look below this line |
70 | 41 ########################################################################## |
0 | 42 set feeds_name "FeedCheck" |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
43 set feeds_message "$feeds_name v0.8 by ccr/TNSP" |
0 | 44 |
45 putlog "$feeds_message" | |
46 bind pub - !feeds feeds_pubfetch | |
47 bind pub - !last feeds_publast | |
48 | |
49 | |
70 | 50 # ------------------------------------------------------------------------ |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
51 proc feeds_escape { str } { |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
52 return [string map {' ''} $str] |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
53 } |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
54 |
0 | 55 proc feeds_smsg {uchan umsg} { |
56 global feeds_preferredmsg | |
57 putserv "$feeds_preferredmsg $uchan :$umsg" | |
58 } | |
59 | |
60 proc feeds_log {umsg} { | |
61 global feeds_name | |
62 putlog "$feeds_name: $umsg" | |
63 } | |
64 | |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
65 proc feeds_msg {utime ufeed uurl utitle} { |
0 | 66 global feeds_channels |
67 foreach {uchan ufilter} [array get feeds_channels] { | |
143 | 68 foreach umatch [split $ufilter "|"] { |
69 if {[string match -nocase $umatch $ufeed]} { | |
226
0ff78e418e77
feeds: Don't add # to channel names automatically.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
70 feeds_smsg "$uchan" "$ufeed: \002$utitle\002 -- $uurl" |
0 | 71 } |
72 } | |
73 } | |
74 } | |
75 | |
76 proc feeds_ctime {utime} { | |
77 if {$utime == "" || $utime == "*"} { | |
78 set utime 0 | |
79 } | |
80 return [clock format $utime -format "%d.%m.%Y %H:%M"] | |
81 } | |
82 | |
83 | |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
84 ### Open database, etc |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
85 if {[catch {sqlite3 feeds_dbh $feeds_dbfile} uerrmsg]} { |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
86 puts "Could not open SQLite3 database '$feeds_dbfile': $uerrmsg." |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
87 exit 2 |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
88 } |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
89 |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
90 |
70 | 91 # ------------------------------------------------------------------------ |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
92 proc feeds_check_start {} { |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
93 global feeds_dbfile |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
94 |
0 | 95 set oldtime 0 |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
96 if {![catch {set ufile [open "$feeds_dbfile.time" r 0600]} uerrmsg]} { |
0 | 97 gets $ufile oldtime |
98 close $ufile | |
99 } else { | |
100 feeds_log "Could not open timefile: $uerrmsg" | |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
101 set oldtime [clock seconds] |
0 | 102 } |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
103 |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
104 return $oldtime |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
105 } |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
106 |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
107 |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
108 proc feeds_check_end {} { |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
109 global feeds_dbfile |
0 | 110 |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
111 if {![catch {set ufile [open "$feeds_dbfile.time" w 0600]} uerrmsg]} { |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
112 puts $ufile [clock seconds] |
0 | 113 close $ufile |
114 } | |
115 } | |
116 | |
70 | 117 # ------------------------------------------------------------------------ |
0 | 118 proc feeds_exec {} { |
154
7a549487fba3
feeds: Cleanups, minor bugfix in feed update checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
119 global feeds_dbh feeds_check_period feeds_running |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
120 |
146
7106dd8db4de
Improve entity parsing, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
145
diff
changeset
|
121 # feeds_log "Timed feed check." |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
122 set oldtime [feeds_check_start] |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
123 set found 0 |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
124 |
142 | 125 set usql "SELECT feed AS ufeed, title AS utitle, url AS uurl, utime AS utime FROM feeds WHERE utime > $oldtime ORDER BY utime ASC" |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
126 feeds_dbh eval $usql { |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
127 feeds_msg $utime $ufeed $uurl $utitle |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
128 set found 1 |
0 | 129 } |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
130 |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
131 if {$found} { |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
132 feeds_check_end |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
133 } |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
134 |
144 | 135 set feeds_running [clock seconds] |
136 timer $feeds_check_period feeds_exec | |
0 | 137 } |
138 | |
146
7106dd8db4de
Improve entity parsing, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
145
diff
changeset
|
139 |
144 | 140 if {[info exists feeds_running]} { |
141 set feeds_last [expr [clock seconds] - $feeds_running] | |
142 } else { | |
143 set feeds_last -1 | |
144 } | |
145 | |
146 if {$feeds_last < 0 || $feeds_last > [expr $feeds_check_period * 60]} { | |
0 | 147 feeds_log "Starting timed feed check." |
154
7a549487fba3
feeds: Cleanups, minor bugfix in feed update checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
148 feeds_exec |
0 | 149 } |
150 | |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
151 |
70 | 152 # ------------------------------------------------------------------------ |
0 | 153 proc feeds_pubfetch {unick uhost uhand uchan utext} { |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
154 global feeds_dbh |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
155 # feeds_log "Manual check invoked on $uchan." |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
156 |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
157 set oldtime [feeds_check_start] |
142 | 158 set nresult [feeds_dbh onecolumn "SELECT COUNT(*) FROM feeds WHERE utime > $oldtime"] |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
159 |
0 | 160 if {$nresult > 0} { |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
161 feeds_check_end |
0 | 162 if {$nresult >= 20} { |
163 feeds_smsg $uchan "$nresult uutta, tod. näk. epäsynkissä. Ignoorataan." | |
164 } else { | |
142 | 165 set usql "SELECT feed AS ufeed, title AS utitle, url AS uurl, utime AS utime FROM feeds WHERE utime > $oldtime ORDER BY utime ASC" |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
166 feeds_dbh eval $usql { |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
167 feeds_msg $utime $ufeed $uurl $utitle |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
168 set found 1 |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
169 } |
0 | 170 feeds_smsg $uchan "$nresult uutta." |
171 } | |
172 } else { | |
173 feeds_smsg $uchan "Ei uusia." | |
174 } | |
175 } | |
176 | |
177 | |
70 | 178 # ------------------------------------------------------------------------ |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
179 proc feeds_publast {unick uhost uhand uchan utext} { |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
180 global feeds_dbh |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
181 set ufound 0 |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
182 |
142 | 183 set usql "SELECT url AS uurl, feed AS ufeed, title AS utitle, utime AS utime FROM feeds WHERE feed LIKE '%[string tolower [feeds_escape $utext]]%' ORDER BY utime DESC LIMIT 1" |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
184 feeds_dbh eval $usql { |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
185 feeds_smsg $uchan "Uusin '$ufeed' / [feeds_ctime $utime]: $utitle -- $uurl" |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
186 set ufound 1 |
0 | 187 } |
188 | |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
189 if {$ufound == 0} { |
0 | 190 feeds_smsg $uchan "Ei osumia haulla '$utext'." |
191 } | |
192 } |