fixed bug in article insertion
[knntp.git] / nntpup.d
blob2d9d9076d7efceb7b994ad19fcc9affb965f0210
1 /* DigitalMars NNTP reader
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 module nntpup;
20 import std.datetime;
22 import iv.cmdcon;
23 import iv.strex;
24 import iv.vfs;
25 import iv.vfs.io;
27 import nntp;
30 // ////////////////////////////////////////////////////////////////////////// //
31 void main (string[] args) {
32 if (args.length == 1) args ~= ["D", "digitalmars.D.learn", "digitalmars.D", "digitalmars.D.announce", "digitalmars.D.internals"];
34 //auto abase = new ArticleBase("/tmp/D.knmh", "/tmp/D.knmt");
35 foreach (string group; args[1..$]) {
36 writeln("=== GROUP: ", group, " ===");
38 auto abase = new ArticleBase(group);
39 abase.load();
40 scope(exit) delete abase;
42 auto sk = new SocketNNTP("news.digitalmars.com");
43 scope(exit) {
44 if (sk.active) sk.quit();
45 sk.close();
48 sk.selectGroup(group);
50 //writeln("lo=", sk.lowater, "; hi=", sk.hiwater, "; empty=", sk.emptyGroup);
51 if (sk.emptyGroup) continue;
53 uint stnum = abase.maxnum+1;
55 if (abase.alist.length == 0) stnum = (sk.hiwater > 1023 ? sk.hiwater-1023 : 0);
56 if (stnum > sk.hiwater) { writeln("no new articles"); continue; }
58 writeln(sk.hiwater+1-stnum, " new articles");
60 // download new articles
61 foreach (immutable uint anum; stnum..sk.hiwater+1) {
62 import std.conv : to;
63 write("\r[", anum, "/", sk.hiwater, "] ... \x1b[K");
64 auto art = sk.getArticle(anum);
65 if (!art.valid) { writeln("SKIP"); continue; }
66 write("OK");
67 art.flags |= Article.Flag.Unread;
68 abase.insert(art);
69 //abase.selfCheck();
71 writeln;
73 abase.selfCheck();
74 abase.writeUpdates();