Mercurial > hg > egg-tcls
annotate feeds.tcl @ 662:bb6aea76cdb4
feeds: Fix binds to actually work.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 20 Feb 2021 17:35:07 +0200 |
parents | 179fc8150090 |
children | 8bde8f798188 |
rev | line source |
---|---|
70 | 1 ########################################################################## |
0 | 2 # |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
3 # FeedCheck v2.0 by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
578 | 4 # (C) Copyright 2008-2021 Tecnic Software productions (TNSP) |
0 | 5 # |
265
908edc54005a
feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
6 # Requires fetch_feeds.tcl to be run as a cronjob, for example |
908edc54005a
feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
7 # 15 * * * * /absolute/path/to/fetch_feeds.tcl |
0 | 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 |
265
908edc54005a
feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
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:
226
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:
226
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:
226
diff
changeset
|
20 source [file dirname [info script]]/config.feeds |
0 | 21 |
422
880a07485275
Add utl_ctime() to utillib and use it elsewhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
22 ### Required utillib.tcl |
880a07485275
Add utl_ctime() to utillib and use it elsewhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
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:
393
diff
changeset
|
24 |
0 | 25 |
70 | 26 ########################################################################## |
0 | 27 # No need to look below this line |
70 | 28 ########################################################################## |
423
44c9128097cd
feeds: Remember to require sqlite3 package.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
29 package require sqlite3 |
44c9128097cd
feeds: Remember to require sqlite3 package.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
30 |
0 | 31 set feeds_name "FeedCheck" |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
32 set feeds_message "$feeds_name v2.0 by ccr/TNSP" |
0 | 33 |
34 | |
70 | 35 # ------------------------------------------------------------------------ |
557
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
36 ### Utility functions |
0 | 37 proc feeds_log {umsg} { |
550
85fe3bc36307
Rename *_logmsg settings to *_log_enable.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
38 global feeds_log_enable feeds_name |
85fe3bc36307
Rename *_logmsg settings to *_log_enable.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
39 if {$feeds_log_enable != 0} { |
595 | 40 putlog "${feeds_name}: $umsg" |
526
eb9921ae5c7a
feeds: Add feeds_logmsg setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
41 } |
0 | 42 } |
43 | |
534 | 44 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
45 proc feeds_qm {uid} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
46 global feeds_messages |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
47 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
48 if {[info exists feeds_messages($uid)]} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
49 return $feeds_messages($uid) |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
50 } else { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
51 return $uid |
0 | 52 } |
53 } | |
54 | |
55 | |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
56 proc feeds_smsg {apublic anick achan amsg {aargs {}}} { |
564
f85b5c572292
feeds: Add configuration setting feeds_cmd_name.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
57 global feeds_preferredmsg feeds_cmd_name |
f85b5c572292
feeds: Add configuration setting feeds_cmd_name.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
58 set amsg [string map [list "@cmd@" $feeds_cmd_name] $amsg] |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
59 utl_msg_args $feeds_preferredmsg $apublic $anick $achan $amsg $aargs |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
60 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
61 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
62 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
63 proc feeds_msg {apublic anick achan aid {aargs {}}} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
64 feeds_smsg $apublic $anick $achan [feeds_qm $aid] $aargs |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
65 } |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
66 |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
67 |
70 | 68 # ------------------------------------------------------------------------ |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
69 proc feeds_check_do {uforce upublic unick uchan} { |
608 | 70 global feeds_db_file feeds_dbh feeds_sync_limit feeds_channels |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
71 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
72 # Get old time, if it exists |
0 | 73 set oldtime 0 |
608 | 74 if {![catch {set ufile [open "${feeds_db_file}.time" r 0600]} uerrmsg]} { |
0 | 75 gets $ufile oldtime |
76 close $ufile | |
77 } else { | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
78 feeds_log "Could not open timefile for reading: ${uerrmsg}" |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
79 set oldtime [clock seconds] |
0 | 80 } |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
81 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
82 # Check for new items |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
83 set nresults [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
|
84 |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
85 if {$nresults > $feeds_sync_limit} { |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
86 # Too many items, don't spam the channels |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
87 feeds_log "${nresults} new entries since [utl_ctime $oldtime], probably unsynchronized. Ignoring." |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
88 if {$uforce} { |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
89 feeds_msg $upublic $unick $uchan "chk_unsync_entries" [list $nresults [utl_ctime $oldtime]] |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
90 } |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
91 } elseif {$nresults > 0 || $uforce} { |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
92 # Spam the channels with new items |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
93 feeds_log "${nresults} new entries since [utl_ctime $oldtime] .." |
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
94 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
95 if {$uforce} { |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
96 feeds_msg $upublic $unick $uchan "chk_new_entries" [list $nresults [utl_ctime $oldtime] $oldtime] |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
97 } |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
98 |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
99 set usql "SELECT feed AS ufeed, title AS utitle, url AS uurl, utime AS utime FROM feeds WHERE utime > $oldtime ORDER BY utime ASC" |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
100 feeds_dbh eval $usql { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
101 # Message all relevant channels |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
102 foreach {qchan ufilter} [array get feeds_channels] { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
103 foreach umatch [split $ufilter "|"] { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
104 if {[string match -nocase $umatch $ufeed]} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
105 feeds_msg 1 "NULL" $qchan "chk_entry" [list $ufeed $utitle $uurl [utl_ctime $utime]] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
106 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
107 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
108 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
109 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
110 } |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
423
diff
changeset
|
111 |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
112 if {$nresults > 0} { |
605
1d39db72e190
feeds: Rename SQLite3 database filename configuration variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
596
diff
changeset
|
113 if {![catch {set ufile [open "${feeds_db_file}.time" w 0600]} uerrmsg]} { |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
114 puts $ufile [clock seconds] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
115 close $ufile |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
116 } else { |
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
117 feeds_log "Could not write timefile: ${uerrmsg}" |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
118 } |
0 | 119 } |
120 } | |
121 | |
534 | 122 |
0 | 123 proc feeds_exec {} { |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
124 global feeds_check_period feeds_running |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
423
diff
changeset
|
125 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
126 feeds_check_do 0 0 "NULL" "NULL" |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
127 |
144 | 128 set feeds_running [clock seconds] |
129 timer $feeds_check_period feeds_exec | |
0 | 130 } |
131 | |
146
7106dd8db4de
Improve entity parsing, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
145
diff
changeset
|
132 |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
133 proc feeds_validate_name {upublic unick uchan upattern ufname} { |
565 | 134 global feeds_dbh |
596 | 135 upvar $ufname afname |
565 | 136 |
137 # Check value | |
138 if {$upattern == ""} { | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
139 set afname "" |
565 | 140 return 1 |
141 } | |
142 | |
143 # Check if there are multiple matches | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
144 set usql "SELECT COUNT(DISTINCT(feed)) AS nfeeds,feed AS afname FROM feeds WHERE feed LIKE '%[utl_escape $upattern]%'" |
565 | 145 feeds_dbh eval $usql {} |
146 | |
147 if {$nfeeds > 1} { | |
148 feeds_msg $upublic $unick $uchan "multiple_matches" [list $upattern] | |
149 return 0 | |
150 } elseif {$nfeeds == 0} { | |
151 feeds_msg $upublic $unick $uchan "no_matches" [list $upattern] | |
152 return 0 | |
153 } else { | |
154 return 1 | |
155 } | |
156 } | |
157 | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
158 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
159 # ------------------------------------------------------------------------ |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
160 proc feeds_cmd {unick uhost uhand uchan uargs upublic} { |
565 | 161 global feeds_dbh feeds_messages feeds_history_limit |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
162 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
163 # Check and handle arguments |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
164 set rarglist [::textutil::split::splitx $uargs {\s+}] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
165 set rcmd [lindex $rarglist 0] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
166 set rargs [lrange $rarglist 1 end] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
167 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
168 if {$rcmd == "?" || $rcmd == "help" || $rcmd == "apua"} { |
557
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
169 foreach ukey $feeds_messages(help_full) { |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
170 feeds_msg $upublic $unick $uchan $ukey |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
171 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
172 return 0 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
173 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
174 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
175 if {$rcmd == "last" || $rcmd == "latest" || $rcmd == "uusin"} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
176 # Show latest entry or latest entry of specified feed |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
177 set ufound 0 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
178 set utext [string tolower [join $rargs " "]] |
565 | 179 |
180 # Validate feed name | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
181 if {![feeds_validate_name $upublic $unick $uchan $utext fname]} { |
565 | 182 return 0 |
183 } | |
184 | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
185 set usql "SELECT url AS uurl, feed AS ufeed, title AS utitle, utime AS utime FROM feeds WHERE feed LIKE '%[utl_escape $fname]%' ORDER BY utime DESC LIMIT 1" |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
186 feeds_dbh eval $usql { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
187 feeds_msg $upublic $unick $uchan "search_latest_feed" [list $ufeed [utl_ctime $utime] $utitle $uurl] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
188 set ufound 1 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
189 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
190 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
191 if {$ufound == 0} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
192 feeds_msg $upublic $unick $uchan "search_no_matches" [list $utext] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
193 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
194 } elseif {[string match "forc*" $rcmd] || [string match "fet*" $rcmd]} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
195 # Force check for new entries |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
196 if {![matchattr $uhand n]} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
197 feeds_msg $upublic $unick $uchan "no_access" |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
198 } |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
199 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
200 feeds_check_do 1 $upublic $unick $uchan |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
201 } elseif {[string match "list*" $rcmd]} { |
565 | 202 # List feeds |
203 set uarg [lindex $rargs 0] | |
204 | |
205 if {$uarg == "all" || $uarg == "long" || $uarg == "kaikki"} { | |
206 # Long list | |
207 set utext [string tolower [join [lrange $rargs 1 end] " "]] | |
208 | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
209 if {$upublic && ![matchattr $uhand n]} { |
565 | 210 feeds_msg $upublic $unick $uchan "feed_list_long_denied" [list $rcmd $utext] |
211 return 0 | |
212 } | |
213 | |
214 set ulistitem [feeds_qm "feed_list_item_long"] | |
215 set ulistsep [feeds_qm "feed_list_sep_long"] | |
216 | |
217 set usql "SELECT feed AS ufeed, MAX(utime) AS ulatest, MIN(utime) AS uoldest, COUNT(feed) AS nitems FROM feeds WHERE feed LIKE '%[utl_escape $utext]%' GROUP BY feed" | |
218 set ulist {} | |
219 | |
220 feeds_dbh eval $usql { | |
221 lappend ulist [utl_str_map_values $ulistitem [list $ufeed [utl_ctime $ulatest] [utl_ctime $uoldest] $nitems]] | |
222 } | |
223 | |
224 if {$utext != ""} { | |
225 feeds_msg $upublic $unick $uchan "feed_list_filter" [list $utext [join $ulist $ulistsep]] | |
226 } else { | |
227 feeds_msg $upublic $unick $uchan "feed_list_all" [list [join $ulist $ulistsep]] | |
228 } | |
229 } elseif {$uarg != ""} { | |
230 # List feeds with a name filter | |
231 set utext [string tolower [join $rargs " "]] | |
232 | |
233 set ulistitem [feeds_qm "feed_list_item_short"] | |
234 set ulistsep [feeds_qm "feed_list_sep_short"] | |
235 | |
236 set usql "SELECT feed AS ufeed, MAX(utime) AS ulatest, MIN(utime) AS uoldest, COUNT(feed) AS nitems FROM feeds WHERE feed LIKE '%[utl_escape $utext]%' GROUP BY feed" | |
237 set ulist {} | |
238 | |
239 feeds_dbh eval $usql { | |
240 lappend ulist [utl_str_map_values $ulistitem [list $ufeed [utl_ctime $ulatest] [utl_ctime $uoldest] $nitems]] | |
241 } | |
242 | |
243 feeds_msg $upublic $unick $uchan "feed_list_filter" [list $utext [join $ulist $ulistsep]] | |
244 } else { | |
245 # List any active feeds | |
246 set uold [expr [clock seconds] - 60*60*24*365] | |
247 | |
248 set ulistitem [feeds_qm "feed_list_item_short"] | |
249 set ulistsep [feeds_qm "feed_list_sep_short"] | |
250 | |
251 set usql "SELECT feed AS ufeed, MAX(utime) AS ulatest, MIN(utime) AS uoldest, COUNT(feed) AS nitems FROM feeds GROUP BY feed HAVING ulatest >= $uold" | |
252 set ulist {} | |
253 | |
254 feeds_dbh eval $usql { | |
255 lappend ulist [utl_str_map_values $ulistitem [list $ufeed [utl_ctime $ulatest] [utl_ctime $uoldest] $nitems]] | |
256 } | |
257 | |
258 feeds_msg $upublic $unick $uchan "feed_list_active" [list [utl_ctime $uold] [join $ulist $ulistsep]] | |
259 } | |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
260 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
261 } elseif {[string match "hist*" $rcmd]} { |
565 | 262 # Show history of a feed |
263 if {[llength $rarglist] < 2} { | |
264 feeds_msg $upublic $unick $uchan "help_history" | |
265 return 0 | |
266 } | |
267 | |
268 set utext [string tolower [join $rargs " "]] | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
269 if {$upublic && ![matchattr $uhand n]} { |
565 | 270 feeds_msg $upublic $unick $uchan "feed_list_long_denied" [list $rcmd $utext] |
271 return 0 | |
272 } | |
273 | |
274 # Validate feed name | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
275 if {![feeds_validate_name $upublic $unick $uchan $utext fname]} { |
565 | 276 return 0 |
277 } | |
278 | |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
279 set ulistitem [feeds_qm "history_list_item"] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
280 set ulistsep [feeds_qm "history_list_sep"] |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
281 set usql "SELECT url AS uurl, title AS utitle, utime FROM feeds WHERE feed='[utl_escape $fname]' ORDER BY utime DESC LIMIT ${feeds_history_limit}" |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
282 set ulist {} |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
283 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
284 feeds_dbh eval $usql { |
565 | 285 lappend ulist [utl_str_map_values $ulistitem [list $uurl $utitle [utl_ctime $utime]]] |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
286 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
287 |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
288 feeds_msg $upublic $unick $uchan "history_list" [list $fname [join $ulist $ulistsep]] |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
289 } else { |
557
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
290 # Help/usage |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
291 feeds_msg $upublic $unick $uchan "help_short" |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
292 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
293 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
294 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
295 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
296 #------------------------------------------------------------------------- |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
297 proc feeds_cmd_pub {unick uhost uhand uchan uargs} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
298 global feeds_channels |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
299 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
300 foreach {ukey uvalue} [array get feeds_channels] { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
301 if {[string match $ukey $uchan]} { |
662
bb6aea76cdb4
feeds: Fix binds to actually work.
Matti Hamalainen <ccr@tnsp.org>
parents:
608
diff
changeset
|
302 feeds_cmd $unick $uhost $uhand $uchan $uargs 1 |
bb6aea76cdb4
feeds: Fix binds to actually work.
Matti Hamalainen <ccr@tnsp.org>
parents:
608
diff
changeset
|
303 return 1 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
304 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
305 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
306 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
307 return 1 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
308 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
309 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
310 proc feeds_cmd_msg {unick uhost uhand uargs} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
311 feeds_cmd $unick $uhost $uhand "PRIV" $uargs 0 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
312 return 1 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
313 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
314 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
315 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
316 #------------------------------------------------------------------------- |
557
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
317 # Script initialization |
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
318 #------------------------------------------------------------------------- |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
319 putlog "$feeds_message" |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
320 |
605
1d39db72e190
feeds: Rename SQLite3 database filename configuration variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
596
diff
changeset
|
321 if {[catch {sqlite3 feeds_dbh $feeds_db_file} uerrmsg]} { |
1d39db72e190
feeds: Rename SQLite3 database filename configuration variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
596
diff
changeset
|
322 putlog "Could not open SQLite3 database '${feeds_db_file}': ${uerrmsg}" |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
323 exit 2 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
324 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
325 |
144 | 326 if {[info exists feeds_running]} { |
327 set feeds_last [expr [clock seconds] - $feeds_running] | |
328 } else { | |
329 set feeds_last -1 | |
330 } | |
331 | |
332 if {$feeds_last < 0 || $feeds_last > [expr $feeds_check_period * 60]} { | |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
333 putlog " - Starting timed feed check." |
154
7a549487fba3
feeds: Cleanups, minor bugfix in feed update checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
334 feeds_exec |
0 | 335 } |
336 | |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
337 putlog " - Executing feeds_init()" |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
338 feeds_init |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
339 putlog " - feeds_init() done." |
557
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
340 |
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
341 # end of script |