• Home
  • About
  • Archives
  • Book
  • Contact me
  • Photos
  • Projects
  • Talks
Subscribe: Posts | Comments | E-mail
  • ArticlesArticles which I authored
  • GSOCGoogle Summer of code archives
  • HacksExperiments
  • LifeIn and around life
  • Open SourceFree and Open Source Software
  • PardusContributions with Pardus Project

Sarath Lakshman

Posts Tagged ‘script’


Posted on October 28, 2008 - by Sarath

define – A lovely utility

I frequently use Google for finding several definitions. It feels always painful to run browser every time to grab some definitions. Being a terminal lover, I always wanted to do it on commandline. I wrote a few lines of python code, and its done.

I love this utility.
Cheers !

#!/usr/bin/env python
import urllib2,re,sys

def usage():
    if sys.argv.__len__() is not 2:
        print "usage: define < word >\n"
    else:

        txt = define(sys.argv[1])
        if txt is not None:
                print '\n\033[31mDefinition of ' + sys.argv[1].upper() + ':\033[0m\n'+ txt+ '\033[0m\n'
        else:
                print "\nNo definition found\n"

def define(str):
    opener = urllib2.build_opener()
    opener.addheaders = [('User-agent', 'define grabber by t3rm1n4l')]
        try:

        txt=opener.open('http://www.google.com/search?q=define:'+ str)
            txt=txt.read()
            regex = re.compile("<li>[a-zA-Z,. ]*\.\.\.")
            obj = regex.findall(txt)
            return obj[0][4:]
    except:
        pass
usage()

UPDATE: toolz suggested me that it would be nice to print all the definitions avaliable.

So I have updated the script with more options :)

get it here

Google is playing more with User-agent strings. You won’t find same search results for different User-agent strings :) . That’s fun.

$ define keyword -all # for printing all definitions
$ define keyword -4 # For printing 4 definitions
$ define keyword # prints 1 definiton

define utility



  • About

    Sarath Lakshman is a Hactivist of Free and Open Source Software from Kerala.
    Read more about him.
  • My Book

    Solve real-world shell scripting problems with over 110 simple but incredibly effective recipes.



  • Follow

  • Random Photos

  • Tweets

    • Preparing for your first-job interviews:
      http://t.co/SBdRl4At
      2011/11/30 23:31
    • is down. Having some issues with hosting account. I will update when it is back.
      http://t.co/Hj3u1qm1
      2011/11/29 11:59
    • Blog post: Preparing for your first-job interviews:
      http://t.co/SBdRl4At
      2011/11/29 09:47
    • Packt Publishers interviewed me.
      http://t.co/CMrvOPh
      2011/09/08 00:21
  • Calendar

    May 2012
    M T W T F S S
    « Nov    
     123456
    78910111213
    14151617181920
    21222324252627
    28293031  
  • Archives

  • Blogroll

    • FOSS.IN
    • GNU Vision Blog
    • Hiran Effects
    • J5′s blog
    • Pardus planet
    • Praveen Arimbrathodiyil’s blog
    • Santhosh Thottingal
    • SLYNUX GNU Operating System
    • St Josephs HSS, Thalassery – Alumni
    • Swaroop CH
    • TT’s Jottings-Blog of VU2SWX
  • Tags

    algorithm automation bangalore bash bash scripting bug code college contribution define development facebook fedora foss fossmeet freedom free sms freesoftware Friends fun gnome gnu google google summer of code hack hacking hacks internet interview joy kde 4.1.2 kochi Life linux mec microsoft new year night nitc pardus pitivi python script summer of code video editor
Copyright © 2005 - 2010 Sarath Lakshman
Powered by Wordpress 3.04