English to Tamil dictionary via terminal


Simple Installation:

sudo apt-get install python-setuptools
sudo apt-get install python-beautifulsoup

Download code from github https://github.com/sathia27/e2t-dictionary

.Save code in file. then run below code. and then run code.

python tamildict.py

Features:

  • See all words listed with given alphabets.
  • See meaning of given word in tamil.

Bugs:

  • Tamil font was not clear in terminal mode.

Code:


#!/usr/bin/python2.4
# coding=UTF-8
import urllib2
from BeautifulSoup import BeautifulSoup
import re
import codecs
try:
 def alphabets():
 while True:
 try:
 alphabet = raw_input("Enter the alphabet(eg. 'a' or 'b' to get all words.. Type 'quit' for quiting+): ")
 if alphabet == "quit":
 print "\nQuiting!!!\n"
 break
 url = "http://ta.wiktionary.org/wiki/சிறப்பு:PrefixIndex/"+alphabet
 req = urllib2.Request(url, headers={'User-Agent' : "Magic Browser"})
 con = urllib2.urlopen( req )
 soup = BeautifulSoup(con)
 all_words = soup.find("table", {"id" : "mw-prefixindex-list-table"}).findAll("a")
 print "="*40
 print "Words listed for Alphabet %r" %alphabet
 print "="*40+"\n"
 for i in all_words:
 print i.contents[0]
 except KeyboardInterrupt:
 print "\n\nQuitting!!"
 break
 except:
 print "Sorry!! given alphabet %r not found" %alphabet
 print " or some internet connection!!"
 def words():
 while True:
 try:
 word = raw_input("Enter the word:")
 url = "http://ta.wiktionary.org/wiki/"+word
 print url
 req = urllib2.Request(url, headers={'User-Agent' : "Magic Browser"})
 con = urllib2.urlopen( req )
 soup = BeautifulSoup(con)
 meaning_of_word = soup.find("div", {"class":"mw-content-ltr"})
 ul = meaning_of_word.findAll("ul")[1]
 f = open("temp","w")
 for li in ul.findAll(text=True):
 print li
 except KeyboardInterrupt:
 print "\n\nQuitting!!"
 break
 except:
 print "Sorry!! given word %r not found" %word
 print " or some internet connection!!"
 c = raw_input("Enter \n '1' for see all words for given alphabets \n '2' to get meaning of word in tamil\nEnter choice: ")
 if c == "1":
 alphabets()
 if c == "2":
 words()

except KeyboardInterrupt:
 print "\n\nQuitting!!"

Output

Advertisements

About sathia

Web developer at cloudmint
This entry was posted in programs, ubuntu and tagged , , , . Bookmark the permalink.

2 Responses to English to Tamil dictionary via terminal

  1. Tushar Kumar says:

    Nice tip

  2. sanmugasundaramk says:

    good work keep doing :)..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s