Googlism

From s23
Jump to navigation Jump to search

You can use [[Googlism:text]] to do a Googlism:googlism


also i found this googlism.pl its a Perl proggi for getting goolism's found here

#!/usr/bin/perl -w

use strict;
use HTML::Entities;

if( @ARGV < 1 )
{
    die "Insufficient arguments.";
}

my $term = $ARGV[ 0 ];
$term =~ m/^(.+?)[ ?!.]*$/;
$term = $1;
$term =~ s/[^wds]//g;
$term =~ s/s+/+/g;
my $term2 = $term;
$term2 =~ s/+/ /g;

my $command = "curl -m 60 -s "http://www.googlism.com/index.htm?ism="
    . $term
    . "" | egrep -o ""
    . $term2
    . " is .+<br>" > googlism.out";

`$command`;

open( FIN, "<", "googlism.out" );

my $num = 0;
my @results;

while( my $line = <FIN> )
{
    $results[ $num ] = $line;
    $num++;
}

close( FIN );

if( $num > 0 )
{
    my $result = $results[ int( rand( $num ) ) ];
    $result =~ s/<br>//;

    print( decode_entities( $result ) );
}
else
{
    print( "No results for $term.
" );
}

and a nice Python googlism script here

#!/usr/bin/env python

"""
Python and command line access to the wisdom of googlism.com.
"""

import getopt
import urllib
import sys


__program__ = 'googlism'
__version__ = '1.0'
__url__ = 'http://www.alcyone.com/software/googlism/'
__author__ = 'Erik Max Francis <max@alcyone.com>'
__copyright__ = 'Copyright (C) 2004 Erik Max Francis'
__license__ = 'GPL'


AGENT = 'googlism.py/%s' % __version__


class Opener(urllib.FancyURLopener):
    
    version = AGENT
    
    def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)


class Googlism(object):

    TYPES = {'who': '1', 'what': '2', 'where': '3', 'when': '4'}
    DEFAULT_BASE_URL = 'http://www.googlism.com/index.htm'
    DEFAULT_TYPE = 'who'

    def __init__(self, baseUrl=DEFAULT_BASE_URL):
        self.baseUrl = baseUrl
        self.opener = Opener()

    def go(self, query, type=DEFAULT_TYPE):
        url = '%s?ism=%s&type=%s' % (self.baseUrl,
                                     urllib.quote(query),
                                     Googlism.TYPES[type])
        theFile = self.opener.open(url)
        content = theFile.read()
        theFile.close()
        if content.find("doesn't know enough about") >= 0:
            return []
        start = content.find('Googlism for:')
        current = content.find('<br>', start)
        result = []
        while True:
            next = content.find('<br>', current)
            if next < 0:
                break
            fragment = content[current:next].strip()
            if fragment.find('<tr>') >= 0 or fragment.find('<td>') >= 0:
                break
            if fragment:
                result.append(fragment)
            current = next + len('<br>')
        return result


def usage():
    print >> sys.stderr, """
Usage: %(__program__)s [options] <query>

Options:
  -1 --who       Do a "who" query [default]
  -2 --what      Do a "what" query
  -3 --where     Do a "where" query
  -4 --when      Do a "when" query
  -q --quiet     Don't print anything to stderr for empty results
""" % globals()

def main():
    _type = Googlism.DEFAULT_TYPE
    _verbose = True
    args = sys.argv[1:]
    if not args:
        usage()
        sys.exit()
    pairs, remainder = getopt.getopt(args, '1234q',
                                     ['who', 'what', 'where', 'when', 'quiet'])
    for option, argument in pairs:
        if option in ('-1', '--who'):
            _type = 'who'
        elif option in ('-2', '--what'):
            _type = 'what'
        elif option in ('-3', '--where'):
            _type = 'where'
        elif option in ('-4', '--when'):
            _type = 'when'
        elif option in ('-q', '--quiet'):
            _verbose = False
    _query = ' '.join(remainder)
    googlism = Googlism()
    result = googlism.go(_query, _type)
    if result:
        for line in result:
            print line
        code = 0
    else:
        if _verbose:
            print >> sys.stderr, "No results were found"
        code = 1
    sys.exit(code)

if __name__ == '__main__': main()