]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/Plug.pl
* Add vim formatting comments ( # vim:ts=4:sw=4:expandtab:tw=80 )
[infobot.git] / src / Modules / Plug.pl
1 #
2 #     Plug.pl: hacked for http://Plug.org/ by Tim Riker <Tim@Rikers.org>
3 # Slashdot.pl: Slashdot headline retrival
4 #      Author: Chris Tessone <tessone@imsa.edu>
5 #    Modified: dms
6 #   Licensing: Artistic License (as perl itself)
7 #     Version: v0.4 (19991125)
8 #
9
10 ###
11 # fixed up to use XML'd /. backdoor 7/31 by richardh@rahga.com
12 # My only request if this gets included in infobot is that the
13 # other header gets trimmed to 2 lines, dump the fluff ;) -rah
14 #
15 # added a status message so people know to install LWP - oznoid
16 # also simplified the return code because it wasn't working.
17 ###
18
19
20 package Plug;
21
22 use strict;
23
24 sub plugParse {
25     my @list;
26
27     foreach (@_) {
28         next unless (/<title>(.*?)<\/title>/);
29         my $title = $1;
30         $title =~ s/&amp\;/&/g;
31         push(@list, $title);
32     }
33
34     return @list;
35 }
36
37 sub Plug {
38     my @results = &::getURL("http://www.plug.org/index.xml");
39     my $retval  = "i could not get the headlines.";
40
41     if (scalar @results) {
42         my $prefix      = 'Plug Headlines ';
43         my @list        = &plugParse(@results);
44         $retval         = &::formListReply(0, $prefix, @list);
45     }
46
47     &::performStrictReply($retval);
48 }
49
50 sub plugAnnounce {
51     my $file = "$::param{tempDir}/plug.xml";
52
53     my @Cxml = &::getURL("http://www.plug.org/index.xml");
54     if (!scalar @Cxml) {
55         &::DEBUG("sdA: failure (Cxml == NULL).");
56         return;
57     }
58
59     if (! -e $file) {           # first time run.
60         open(OUT, ">$file");
61         foreach (@Cxml) {
62             print OUT "$_\n";
63         }
64         close OUT;
65
66         return;
67     }
68
69     my @Oxml;
70     open(IN, $file);
71     while (<IN>) {
72         chop;
73         push(@Oxml,$_);
74     }
75     close IN;
76
77     my @Chl = &plugParse(@Cxml);
78     my @Ohl = &plugParse(@Oxml);
79
80     my @new;
81     foreach (@Chl) {
82         last if ($_ eq $Ohl[0]);
83         push(@new, $_);
84     }
85
86     if (scalar @new == 0) {
87         &::status("Plug: no new headlines.");
88         return;
89     }
90
91     if (scalar @new == scalar @Chl) {
92         &::DEBUG("sdA: scalar(new) == scalar(Chl). bad?");
93     }
94
95     open(OUT,">$file");
96     foreach (@Cxml) {
97         print OUT "$_\n";
98     }
99     close OUT;
100
101     return "Plug: ".
102                         join(" \002::\002 ", @new);
103 }
104
105 1;
106
107 # vim:ts=4:sw=4:expandtab:tw=80