Skip to content

Commit

Permalink
Ready to parse HTML. Will do so next commit.
Browse files Browse the repository at this point in the history
(We even get the data every time the search command is given. We just
don't parse it or do anything with it...... Parsing is going to be fun.
\o/)..
  • Loading branch information
Rick E committed Nov 27, 2009
1 parent 9409002 commit 1d37283
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
25 changes: 24 additions & 1 deletion PortLookup.pm
Expand Up @@ -3,6 +3,7 @@

use warnings;
use strict;
use Switch;

package PortLookup;
use LWP::Simple;
Expand Down Expand Up @@ -31,8 +32,30 @@ sub port {
}
}

sub searchports {
sub shortenurl {
my $long_url = shift;
my $short_url;
$short_url = get("http://is.gd/api.php?longurl=$long_url");
if($short_url =~ /The URL you entered is on our blacklist /){
return $long_url;
}
return $short_url;
}

sub portsearch {
my $search_by = shift;
my $keywords = shift;
my $s_cat;
switch($search_by) {
case "maintainer" { $s_cat = 'maintainer'; }
case "keyword" { $s_cat = 'all'; }
case "name" { $s_cat = 'name'; }
case "desc" { $s_cat = 'text'; }
case "description" { $s_cat = 'text'; }
}

my $results = get("http://www.freebsd.org/cgi/ports.cgi?query=$keywords&stype=$s_cat&sektion=all");
return "I exist and you poked me with k:$keywords, s:$search_by, scat:$s_cat";
}

1; # Make perl happy.
8 changes: 8 additions & 0 deletions freebsd.pl
Expand Up @@ -66,6 +66,14 @@ sub said{
}
}

elsif($text =~ /<(keyword|maintainer|desc|description):([\w\d\.\-\_\@\ ]+)>/i){
my $search_by = lc($1);
my $keywords = $2;

# And throw it to portsearch().
return PortLookup::portsearch($search_by, $keywords);
}

elsif($text =~ /\[([a-z]+)\/([\d]+)\]/i){
$self->reply($info,ProblemReport::pr($1,$2));
}
Expand Down

0 comments on commit 1d37283

Please sign in to comment.