]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/zsi.pl
* Add vim formatting comments ( # vim:ts=4:sw=4:expandtab:tw=80 )
[infobot.git] / src / Modules / zsi.pl
1 package zsi;
2
3 # Search Zaurus Software Index (ZSI)
4 # Version 1.0
5 # Released 26 Aug 2002
6
7 # Developed by Darien Kruss <darien@kruss.com>
8 # http://zaurus.kruss.com/
9 # usually hangs out on #zaurus as 'darienm'
10
11 # This script relies on the following page returning results
12 # http://killefiz.de/zaurus/zsibot.php
13 # Returns the 5 latest/newest entries
14
15 # http://killefiz.de/zaurus/zsibot.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 # 'zsi'  or  'zsi <search>'
24
25 # We reply publicly or privately, depending how we were called
26
27 my $no_zsi;
28
29 use strict;
30
31 BEGIN {
32         $no_zsi = 0;
33         eval "use LWP::UserAgent";
34         $no_zsi++ if ($@);
35 }
36
37 sub queryText {
38         my ($query) = @_;
39
40         if ($no_zsi) {
41                 &::status("zsi module requires LWP::UserAgent.");
42                 return '';
43         }
44
45         my $res_return = 5;
46
47         my $ua = new LWP::UserAgent;
48         $ua->proxy('http', $::param{'httpProxy'}) if (&::IsParam('httpProxy'));
49
50         $ua->timeout(10);
51
52         my $searchpath;
53         if ($query) {
54                 $searchpath = "http://killefiz.de/zaurus/zsibot.php?query=$query";
55         } else {
56                 $searchpath = "http://killefiz.de/zaurus/zsibot.php";
57         }
58
59         my $request = new HTTP::Request('GET', "$searchpath");
60         my $response = $ua->request($request);
61
62         if (!$response->is_success) {
63                 return "Something failed in connecting to the ZSI web server. Try again later.";
64         }
65
66         my $content = $response->content;
67
68         if ($content =~ /No entries found/im) {
69                 return "No results were found searching ZSI for '$query'.";
70         }
71
72         my $res_count = 0; #local counter
73         my $res_display = 0; #results displayed
74
75         my @lines = split(/\n/,$content);
76
77         my $result = '';
78         foreach my $line (@lines) {
79                 if (length($line) > 10) {
80                         my ($name, $href, $desc) = split(/\|/,$line);
81
82                         if ($res_count < $res_return) {
83                                 $result .= "$name ($desc) $href : ";
84                                 $res_display ++;
85                         }
86                         $res_count ++;
87                 }
88         }
89
90         if (($query) && ($res_count > $res_display)) {
91                 $result .= "$res_display of $res_count shown. All at http://killefiz.de/zaurus/search.php?q=$query";
92         }
93
94         return $result;
95 }
96
97 sub query {
98         my ($args) = @_;
99         &::performStrictReply(&queryText($args));
100         return;
101 }
102
103 1;
104
105 # vim:ts=4:sw=4:expandtab:tw=80
106
107 __END__