annotate feeds.tcl @ 551:77a8fab2062f

feeds: Cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 08 Jul 2020 22:56:07 +0300
parents 85fe3bc36307
children c9ed23fb6d38
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
15fc72bc3f3e More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
1 ##########################################################################
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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>
523
89aaf279c12b feeds: Bump copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 522
diff changeset
4 # (C) Copyright 2008-2020 Tecnic Software productions (TNSP)
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #
145
c94b4e1a2ed4 Rename some files, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
9 # See also create_feeds_db.tcl OR convert_feeds_db.tcl, as you will
c94b4e1a2ed4 Rename some files, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
10 # need to either create a SQLite3 database or convert old text flat
c94b4e1a2ed4 Rename some files, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
11 # file to SQLite3.
c94b4e1a2ed4 Rename some files, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
12 #
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 # This script is freely distributable under GNU GPL (version 2) license.
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #
70
15fc72bc3f3e More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
15 ##########################################################################
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
265
908edc54005a feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
422
880a07485275 Add utl_ctime() to utillib and use it elsewhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
70
15fc72bc3f3e More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
26 ##########################################################################
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 # No need to look below this line
70
15fc72bc3f3e More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
70
15fc72bc3f3e More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
36 # ------------------------------------------------------------------------
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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} {
526
eb9921ae5c7a feeds: Add feeds_logmsg setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
40 putlog "$feeds_name: $umsg"
eb9921ae5c7a feeds: Add feeds_logmsg setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
41 }
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
534
7512889f7b72 feeds: Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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 {}}} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
57 global feeds_preferredmsg
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
58 set amsg [string map [list "@cmd@" "!feeds"] $amsg]
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
15fc72bc3f3e More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
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} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
70 global feeds_dbfile 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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 set oldtime 0
549
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
74 if {![catch {set ufile [open "${feeds_dbfile}.time" r 0600]} uerrmsg]} {
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 gets $ufile oldtime
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 close $ufile
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 } else {
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 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
79 set oldtime [clock seconds]
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
83 set usql "SELECT feed AS ufeed, title AS utitle, url AS uurl, utime AS utime FROM feeds WHERE utime > $oldtime ORDER BY utime ASC"
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
84 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
85
549
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
86 if {$nresult > $feeds_sync_limit} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
87 # Too many items, don't spam the channels
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
88 feeds_log "${nresult} new entries since [utl_ctime $oldtime], probably unsynchronized. Ignoring."
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
89 if {$uforce} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
90 feeds_msg $upublic $unick $uchan "chk_unsync_entries" [list $nresult $oldtime [utl_ctime $oldtime]]
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
91 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
92 } else {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
93 # Spam the channels with new items
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
94 feeds_log "${nresult} new entries since [utl_ctime $oldtime] .."
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
95 if {$uforce} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
96 feeds_msg $upublic $unick $uchan "chk_new_entries" [list $nresult [utl_ctime $oldtime]]
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
549
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
99 feeds_dbh eval $usql {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
100 # Message all relevant channels
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
101 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
102 foreach umatch [split $ufilter "|"] {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
103 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
104 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
105 }
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 }
424
825cac46b1cb Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 423
diff changeset
110
549
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
111 if {$nresult > 0} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
112 if {![catch {set ufile [open "${feeds_dbfile}.time" w 0600]} uerrmsg]} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
113 puts $ufile [clock seconds]
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
114 close $ufile
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
115 }
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118
534
7512889f7b72 feeds: Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
119
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 proc feeds_exec {} {
549
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
121 global feeds_check_period feeds_running
424
825cac46b1cb Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 423
diff changeset
122
549
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
123 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
124
144
Matti Hamalainen <ccr@tnsp.org>
parents: 143
diff changeset
125 set feeds_running [clock seconds]
Matti Hamalainen <ccr@tnsp.org>
parents: 143
diff changeset
126 timer $feeds_check_period feeds_exec
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
146
7106dd8db4de Improve entity parsing, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
129
549
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
130 # ------------------------------------------------------------------------
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
131 proc feeds_cmd {unick uhost uhand uchan uargs upublic} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
132 global feeds_dbh feeds_messages
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
133
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
134 # Check and handle arguments
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
135 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
136 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
137 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
138
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
139 if {$rcmd == "?" || $rcmd == "help" || $rcmd == "apua"} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
140 foreach ukey $feeds_messages(usage_full) {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
141 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
142 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
143 return 0
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
144 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
145
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
146 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
147 # 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
148 set ufound 0
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
149 set utext [string tolower [join $rargs " "]]
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
150 set usql "SELECT url AS uurl, feed AS ufeed, title AS utitle, utime AS utime FROM feeds WHERE feed LIKE '%[utl_escape $utext]%' ORDER BY utime DESC LIMIT 1"
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
151 feeds_dbh eval $usql {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
152 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
153 set ufound 1
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
154 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
155
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
156 if {$ufound == 0} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
157 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
158 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
159 } 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
160 # 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
161 if {![matchattr $uhand n]} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
162 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
163 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
164 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
165 } elseif {[string match "list*" $rcmd]} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
166 # List ...
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
167 feeds_smsg $upublic $unick $uchan "usage_help"
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
168
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
169 } elseif {[string match "hist*" $rcmd]} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
170 # Show history of feeds
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
171 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
172 set ulistsep [feeds_qm "history_list_sep"]
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
173 set usql "SELECT feed AS ufeed, utime FROM feeds GROUP BY feed ORDER BY utime DESC,feed DESC"
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
174 set ulist {}
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
175
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
176 feeds_dbh eval $usql {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
177 lappend ulist [utl_str_map_values $ulistitem [list $ufeed [utl_ctime $utime]]]
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
178 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
179
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
180 feeds_msg $upublic $unick $uchan "history_list" [list [join $ulist $ulistsep]]
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
181 } else {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
182 feeds_msg $upublic $unick $uchan "usage_help"
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
183 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
184 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
185
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
186
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
187 #-------------------------------------------------------------------------
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
188 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
189 global feeds_channels
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 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
192 if {[string match $ukey $uchan]} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
193 return [feeds_cmd $unick $uhost $uhand $uchan $uargs 1]
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
194 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
195 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
196
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
197 return 1
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
198 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
199
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
200 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
201 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
202 return 1
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
203 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
204
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
205
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
206 #-------------------------------------------------------------------------
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
207 proc feeds_cmdm_split {uargs} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
208 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
209 return [join [lrange $rarglist 1 end] " "]
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
210 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
211
551
77a8fab2062f feeds: Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 550
diff changeset
212
549
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
213 proc feeds_cmd_pubm {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
214 return [feeds_cmd_pub $unick $uhost $uhand $uchan [feeds_cmdm_split $uargs]]
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
215 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
216
551
77a8fab2062f feeds: Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 550
diff changeset
217
549
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
218 proc feeds_cmd_msgm {unick uhost uhand uargs} {
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
219 return [feeds_cmd_msg $unick $uhost $uhand [feeds_cmdm_split $uargs]]
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
220 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
221
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
222
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
223 # ------------------------------------------------------------------------
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
224 ###
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
225 ### Initializing ..
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
226 ###
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
227 putlog "$feeds_message"
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
228
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
229 if {[catch {sqlite3 feeds_dbh $feeds_dbfile} uerrmsg]} {
551
77a8fab2062f feeds: Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 550
diff changeset
230 putlog "Could not open SQLite3 database '${feeds_dbfile}': ${uerrmsg}."
549
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
231 exit 2
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
232 }
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
233
144
Matti Hamalainen <ccr@tnsp.org>
parents: 143
diff changeset
234 if {[info exists feeds_running]} {
Matti Hamalainen <ccr@tnsp.org>
parents: 143
diff changeset
235 set feeds_last [expr [clock seconds] - $feeds_running]
Matti Hamalainen <ccr@tnsp.org>
parents: 143
diff changeset
236 } else {
Matti Hamalainen <ccr@tnsp.org>
parents: 143
diff changeset
237 set feeds_last -1
Matti Hamalainen <ccr@tnsp.org>
parents: 143
diff changeset
238 }
Matti Hamalainen <ccr@tnsp.org>
parents: 143
diff changeset
239
Matti Hamalainen <ccr@tnsp.org>
parents: 143
diff changeset
240 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
241 putlog " - Starting timed feed check."
154
7a549487fba3 feeds: Cleanups, minor bugfix in feed update checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
242 feeds_exec
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244
549
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
245 putlog " - Executing feeds_init()"
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
246 feeds_init
c6f389bef58e feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
247 putlog " - feeds_init() done."