[Konversation-devel] [Bug 99354] Googling from the input box

ismail donmez ( cartman ) ismail at kde.org
Thu Jul 1 15:59:28 CEST 2010


https://bugs.kde.org/show_bug.cgi?id=99354





--- Comment #6 from ismail ( cartman ) donmez <ismail kde org>  2010-07-01 15:59:22 ---

    A     scripts/google     [License: Trivialfile.]

commit 551c7d287bd905882c9310c4fdc00c9a67ed992d
Author: İsmail Dönmez <ismail at kde.org>
Date:   Sat Feb 19 09:38:55 2005 +0000

    A google script. Launches konqueror with google search url.Try /google kde
    BUG:99354
    FEATURE:

    svn path=/trunk/kdeextragear-2/konversation/; revision=390828

diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index dc15c2c..af63141 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -1,4 +1,4 @@
 scriptsdir=$(kde_datadir)/konversation/scripts
-scripts_SCRIPTS=bug fortune gauge uptime kdeversion cmd sayclip weather
colorizer sysinfo media mail
+scripts_SCRIPTS=bug fortune gauge uptime kdeversion cmd sayclip weather
colorizer sysinfo media mail google
 scripts_DATA=fortunes.dat

diff --git a/scripts/google b/scripts/google
new file mode 100755
index 0000000..af902ee
--- /dev/null
+++ b/scripts/google
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl
+#
+# Copyright (C) 2004 by İsmail Dönmez
+# Licensed under GPL v2 or later at your option
+
+use warnings;
+use strict;
+
+my $PORT= shift;
+shift;
+shift;
+my $url="http://www.google.com/search?q=";
+
+if(!@ARGV)
+{
+    exec 'dcop', $PORT, 'Konversation', 'error', 'Please provide a query, e.g
/google linux';
+}
+else
+{
+    $url="$url at ARGV";
+    exec 'kfmclient','openURL',$url;
+}

--- Comment #7 from ismail ( cartman ) donmez <ismail kde org>  2010-07-01 15:59:23 ---
commit 018ed4cbc8abb07e2a010db297515c8cc3ccac16
Author: İsmail Dönmez <ismail at kde.org>
Date:   Sat Feb 19 14:05:04 2005 +0000

    A better google script using Google SOAP api.
    You need to get a license key from http://api.google.com/createkey
    and put it in ~/.googlekey .Here is the sample usage:
    /google (-s) foo # Searches for foo and displays top 10 results
    /google -s|--spell foo # Spellcheck foo using Google
    /google -b|--browser foo # Launch konqueror and show google search page for
foo

    TODO: Handle errors: Soap exceptions,Non-existent license,no results etc
          Queries containing & doesn't seem to work
    CCBUG:99354
    FEATURE:

    svn path=/trunk/kdeextragear-2/konversation/; revision=390904

diff --git a/scripts/google b/scripts/google
index af902ee..2107bdb 100755
--- a/scripts/google
+++ b/scripts/google
@@ -1,22 +1,59 @@
 #!/usr/bin/env perl
-#
-# Copyright (C) 2004 by İsmail Dönmez
-# Licensed under GPL v2 or later at your option

 use warnings;
-use strict;
+use SOAP::Lite;
+use Getopt::Long;
+ 
+my $PORT=shift;
+my $SERVER=shift;
+my $TARGET=shift;
+my $key=`cat ~/.googlekey`;
+my $googleSearch;
+my $result;
+my $print;
+my $spell;

-my $PORT= shift;
-shift;
-shift;
-my $url="http://www.google.com/search?q=";
+GetOptions('search=s' => \$search,
+       'spell=s' => \$spellcheck,
+       'browser' => \$browser);

-if(!@ARGV)
+if(!$browser && !$search && !$spellcheck && !@ARGV)
 {
-    exec 'dcop', $PORT, 'Konversation', 'error', 'Please provide a query, e.g
/google linux';
+    $info = "/google (-s) <keyword> : Search for keyword at Google, /google
-s|--spell <word> : Spellcheck word using Google, /google -b <keyword> : Show
results in konqueror";
+    exec 'dcop', $PORT, 'Konversation', 'info', $info;
 }
-else
+elsif($browser)
 {
-    $url="$url at ARGV";
+    $query = join(" ", at ARGV);
+    $query =~ s/\&/\%26/g;
+    $url="http://www.google.com/search?q=$query";
     exec 'kfmclient','openURL',$url;
 }
+elsif($search || !$spellcheck)
+{
+    $search = join(" ",$search, at ARGV);
+    
+    system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET, "Searching
Google for %B$search%B ...";
+    
+    $googleSearch =
SOAP::Lite->service("http://api.google.com/GoogleSearch.wsdl"); 
+    $result = $googleSearch->doGoogleSearch($key, $search, 0, 10, "false", "",
"false", "", "UTF-8", "UTF-8"); 
+
+    system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET, "Results
%B1-10%B of about %B$result->{estimatedTotalResultsCount}%B for %B$search%B
(%B$result->{searchTime}%B seconds)";
+    
+    foreach $result (@{$result->{resultElements}})
+    {
+    $print = $result->{URL}." (".$result->{title}.")";
+    $print =~ s/\<b\>/\%B/g;
+    $print =~ s/\<\/b\>/\%B/g;
+    system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET, $print;
+    }
+}
+elsif($spellcheck)
+{
+    $spellcheck = join(" ",$spellcheck, at ARGV);
+    system 'dcop', $PORT, 'Konversation', 'say', $SERVER,
$TARGET,"Spellchecking %B$spellcheck%B ...";
+    $googleSearch =
SOAP::Lite->service("http://api.google.com/GoogleSearch.wsdl"); 
+    $spell = $googleSearch->doSpellingSuggestion($key, $spellcheck);
+    $spell = "Spelling suggestion: ".$spell;
+    system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET,$spell;
+}

-- 
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the Konversation-devel mailing list