]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/zfi.pl
single line for now
[infobot.git] / src / Modules / zfi.pl
1 package zfi;
2
3 # Search Zaurus Feeds Index (ZFI)
4 # Version 1.0
5 # Released 02 Oct 2002
6
7 # Based on ZSI package by Darien Kruss <darien@kruss.com>
8 # Modified by Jordan Wiens <jordan@d0pe.com> (numatrix on #zaurus) and
9 # Eric Lin <anselor@d0pe.com> (anselor on #zaurus) to search ZFI instead of ZSI
10
11 # This script relies on the following page returning results
12 # http://zaurii.com/zfi/zfibot.php
13 # Returns the 5 latest/newest entries
14
15 # http://zaurii.com/zfi/zfibot.php?query=XXXX
16 # Returns all matches where XXX is in the name, description, etc
17
18 # Returned matches are pipe-separated, one record per line
19 # name|URL|description
20
21 # These are the phrases we get called for:
22
23 # 'zfi'  or  'zfi <search>'
24
25 # We reply publicly or privately, depending how we were called
26
27 my $no_zfi;
28
29 BEGIN {
30         $no_zfi = 0;
31         eval "use LWP::UserAgent";
32         $no_zfi++ if ($@);
33 }
34
35 sub queryText {
36         my ($query) = @_;
37
38         if ($no_zfi) {
39                 &main::status("zfi module requires LWP::UserAgent.");
40                 return '';
41         }
42
43         my $res_return = 5;
44
45         my $ua = new LWP::UserAgent;
46   $ua->proxy('http', $::param{'httpProxy'}) if (&::IsParam("httpProxy"));
47
48         $ua->timeout(10);
49
50         my $searchpath;
51         if ($query) {
52                 $searchpath = "http://zaurii.com/zfi/zfibot.php?query=$query";
53         } else {
54                 $searchpath = "http://zaurii.com/zfi/zfibot.php";
55         }
56
57         my $request = new HTTP::Request('GET', "$searchpath");
58         my $response = $ua->request($request); 
59
60         if (!$response->is_success) {
61                 return "Something failed in connecting to the ZFI web server. Try again later.";
62         }
63
64         my $content = $response->content;
65
66         if ($content =~ /No entries found/im) {
67                 return "$result No results were found searching ZFI for '$query'.";
68         }
69
70         my $res_count = 0; #local counter
71         my $res_display = 0; #results displayed
72
73         my @lines = split(/\n/,$content);
74
75         my $result = '';
76         foreach $line(@lines) {
77                 if (length($line) > 10) {
78                         my ($name, $href, $desc) = split(/\|/,$line);
79
80                         if ($res_count < $res_return) {
81                                 $result .= "$name ($desc) $href : ";
82                                 $res_display ++;
83                         }
84                         $res_count ++;
85                 }
86         }
87
88         if (($query) && ($res_count > $res_display)) {
89                 $result .= "$res_display of $res_count shown. All at http://zaurii.com/zfi/index.phtml?p=r&r=$query";
90         }
91
92         return $result;
93 }
94
95 sub query {
96         my ($args) = @_;
97         &::performStrictReply(&queryText($args));
98   return;
99 }
100
101 1;
102 # vim: shiftwidth=2 tabstop=2
103 __END__