User Control Panel
Advertisements

HELP US, HELP YOU!

Dict Service Probs

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Services
View unanswered posts
Author Message
draget
Not Yet a God
Not Yet a God


Joined: 29 Dec 2004
Posts: 367
Location: Australia
Reputation: 32.2Reputation: 32.2Reputation: 32.2

PostPosted: Wed Mar 23, 2005 9:31 am    Post subject: Reply with quote

Code:
#!/usr/bin/perl -wT<br /><br />use CGI qw(:standard);<br />use CGI::Carp qw(warningsToBrowser fatalsToBrowser);<br /><br />use LWP::UserAgent;<br /><br />use lib './lib';<br /><br />my $msg = param('term');<br />print header;<br /><br /># Stuff<br />     $define = DoGet('http://www.google.com/search?hl=en&lr=&ie=ISO-8859-1&q=define+' . $msg);<br />    $reply = GetBetween($define, "lue.gif width\=40 height\=30><td valign\=top><font size\=-1>", "<br><font color\=green>");<br />     $reply = '0sad0 No definition found sorry.' if($reply =~ /did not match any documents./i);<br /><br />print "$reply";<br /><br />sub DoGet {<br />$url = shift;<br /><br />   $ua = LWP::UserAgent->new;<br />   $ua->timeout(30);<br />   $agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';<br />   $ua->agent($agent);<br />   $resp = $ua->get($url);<br /><br />   if($resp->is_success) {<br />  $data = $resp->content;<br />   } else {<br />  print "Failed!!";<br />   }<br /><br />   return $data;<br />}<br /><br />sub GetBetween {<br />   my $string = shift || return;<br />   my $start  = shift;<br />   my $end    = shift;<br />   my $keep_start = shift || 0;<br />   my $keep_end  = shift || 0;<br /><br />   my $pos1 = ($start ? index($string, $start) + length($start) : 0);  return if($pos1 == -1);<br />   my $pos2 = ($end ? index($string, $end, $pos1) : 0);    return if($pos2 == -1);<br /><br />   $string = ($end ? substr($string, $pos1, $pos2 - $pos1) : substr($string, $pos1));<br />   return ($keep_start ? $start : "") . $string . ($keep_end ? $end : "");<br />}<br /><br />


The code was given to me by Matt007 and i am making it into a service (his is now offline).

Yet each time its fun it 'fails' the useragent get. i have printed variables all over the place and it seems in order.

Any ideas?


NB: the lib folder contains, LWP, which i grabbed from my perl site/lib folder.
it didn't work without that there either........
Back to top
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Wed Mar 23, 2005 12:43 pm    Post subject: Reply with quote

Is this a dictionary service or a Google search service? Because what it's doing is getting a Google search results page. Shouldn't it be getting a page from a dictionary site? Because that way it could actually tell you the definition over MSN and not have to send you a "Click here to go to a site with the definition for $msg".

I'll help you out a little by showing some code I have for using dictionary.com to get a definition:
Code:
sub define {<br />     my ($self,$client,$msg) = @_;<br /><br />     # If there's a message to define...<br />     if (length $msg > 0) {<br />          my $src = LWP::Simple::get "http://dictionary.reference.com/search?q=$msg" or return "Could not get dictionary!";<br />          $src =~ s/\n/ /g;<br /><br />          # Get the first definition.<br />          if ($src =~ /<OL><LI>(.*?)<\/LI>/i) {<br />               my $def = $1;<br /><br />               return "Dictionary.com defines $msg as:\n\n"<br />                    . "1. $def";<br />          }<br />          else {<br />               return "Could not obtain the definition to $msg!";<br />          }<br />     }<br />     else {<br />          return "Please provide a message when calling this command.";<br />     }<br />}

_________________
Current Site (2008) http://www.cuvou.com/
Back to top
mat007
Almost An Agent
Almost An Agent


Joined: 12 Jan 2004
Posts: 1375

Reputation: 15.8Reputation: 15.8
votes: 2

PostPosted: Wed Mar 23, 2005 1:13 pm    Post subject: Reply with quote

Google define is perfect just type in define (Not for SOAP tho)

If you have SSH access go to SSH and type cpan do the config.. type

'install LWP-UserAgent'

is header a constant?
Back to top
draget
Not Yet a God
Not Yet a God


Joined: 29 Dec 2004
Posts: 367
Location: Australia
Reputation: 32.2Reputation: 32.2Reputation: 32.2

PostPosted: Wed Mar 23, 2005 1:47 pm    Post subject: Reply with quote

Header is a CGI thing.


Think i forgot to CHMOD the modules.
Back to top
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Wed Mar 23, 2005 7:38 pm    Post subject: Reply with quote

QUOTE(draget @ Mar 23 2005, 08:47 AM)
Header is a CGI thing.


Think i forgot to CHMOD the modules.
[right][snapback]47197[/snapback][/right]


Hm, I've never had to CHMOD modules (my site engine uses Mail::Sendmail for e-mail sending, I just uploaded it to its local lib and it runs fine).

_________________
Current Site (2008) http://www.cuvou.com/
Back to top
draget
Not Yet a God
Not Yet a God


Joined: 29 Dec 2004
Posts: 367
Location: Australia
Reputation: 32.2Reputation: 32.2Reputation: 32.2

PostPosted: Thu Mar 24, 2005 8:38 am    Post subject: Reply with quote

EDIT: WAS working bhut is being evil again.
im getting there, sorry.



Works now.

Wasn't a case of CHMOD'ding in the end.


Was a mistake in my sites lib folder configuration.


anyways.

http://www.members.iinet.net.au/~drage/oth...e.cgi?term=frog

It is a dictionary service, quite good, (some people may have used an old plazma service, this is it, the original went down).
Thanks to Mat007 for basic code!
Back to top
draget
Not Yet a God
Not Yet a God


Joined: 29 Dec 2004
Posts: 367
Location: Australia
Reputation: 32.2Reputation: 32.2Reputation: 32.2

PostPosted: Sat May 14, 2005 10:34 am    Post subject: Reply with quote

fixed!






http://66.246.225.128/~dragese/dict_service.cgi?word=dog

returns:

a member of the genus Canis (probably descended from the common wolf) that has been domesticated by man since prehistoric times; occurs in many breeds; "the dog barked all night"

have fun!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Services All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group