Experience in conducting workshop

Mr. Thyagarajan Shanmugam, CEO of open vidhya (my mentor) conducted workshop in Coimbatore institute of technology on September 1st and 2nd 2012. He took class on PHP and Ruby. Some basic on Ruby on rails. Students in CIT were eager in learning new technology. Me also helped some students by clearing some doubts. Here are some clicks http://openvidya.fossfactory.in/workshops/index.php/Workshop-on-Web-programming-with-Foss-Tools-CIT-coimbatore

Advertisements
| Leave a comment

English to tamil offline dictionary

Code was written in ruby,

Database: sqlite3

Download Files here

File: word.rb

Connecting database using sqlite3 adbapter and active_record ORM.

File: install.sh [only for debian package]

run install.sh

$sh install.sh

Others should install

ruby, rubygems

gems: sqlite3, active_record, nokogiri

File: upload.rb

You dont need to run this script. if you have word.db file. This ruby program scraps

all word and meaning from http://ta.wiktionary.org/wiki/%E0%AE%AE%E0%AF%81%E0%AE%A4%E0%AE%B1%E0%AF%8D_%E0%AE%AA%E0%AE%95%E0%AF%8D%E0%AE%95%E0%AE%AE%E0%AF%8D

and save into sqlite database.

File: word.db

This is database of all words and meanings  which was saved by upload.rb script.

This application has autocomplete functionality.

This is first version of script. code was in repo, url: https://github.com/sathia27/dictionary

Feel free to edit the code. You can change to any languange instead of tamil by making some changes to upload.rb.

How to run

After installation,

Go to that folder and run dict.rb

$cd dictionary
$ruby dict.rb

Screenshots

This slideshow requires JavaScript.

Posted in programs, ubuntu | Tagged , , , , , , , , , | 9 Comments

English to Tamil Translator script

Hi friends,

Started creating translator script in ruby,

which will convert to english document file to tamil pdf file.

Main idea of script is to convert English pdf to Tamil Pdf

So its easy to translate e-book easily to our mother tongue language.’

I just now started with tamil font. This will translate English doc to

Tamil using google translator http://translate.google.com/

Current Status:

*Now it gets .doc extension file from user and it converts to tamil pdf.

Need to changed as English pdf to Tamil pdf.

Note: It has many grammar mistakes while translating. and this is translated to tamil by http://translate.google.com/ Code was in github account : https://github.com/sathia27/Translate-script

If you like to start working in this code. You can take code form github acconut.

If you feel any good method other than this, Please give me suggestion.

Thank you in advance.


#!/usr/bin/env ruby
=begin
Program name: Translation script
Date Written: 05/12/2011
Date Modified: 05/12/2011
Author : Sathianarayanan.S
License: GPL2.0
Version: 1.0
=end
begin
 require 'rubygems'
 require 'nokogiri'
 require 'open-uri'
 require 'net/http'
 require 'uri'
 require 'prawn'
 if ARGV[0]
 puts "converting file '"+ARGV[0]+"' to tamil version!!!"
 resume = File.open(ARGV[0]);
 total_text = ""
 resume.each do |str|
 total_text += str
 end
 page = Nokogiri::HTML(open(URI.parse(URI.encode("http://translate.google.com/?langpair=en|ta&text=#{total_text}"))))
 puts resume.readlines
 result = page.search("#result_box")
 Prawn::Document.generate("output.pdf") do
 font "ttf-tamil-fonts/TAMu_Kalyani.ttf"
 text result.text, :size => 20
 end
 else
 puts "Enter file name. Filename can be .doc or .txt \n[Usage] ruby translate.rb filename.doc"
 end
end

Posted in programs, ubuntu | Tagged , , , , , , , , | 7 Comments

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

Posted in programs, ubuntu | Tagged , , , | 2 Comments

TBus version 1 – Search bus routes from terminal

TBus is script used to see bus routes inside cities.

Now this script is available for cities of bangalore and chennai.

Installation

sudo apt-get install ruby libxml2 libxml2-dev libxslt-dev ruby-dev

sudo apt-get install rubygems

sudo gem install nokogiri

code for TBus:

#!/usr/bin/env ruby
=begin
Program name: Lbus
Date Written: 06/09/2011
Date Modified: 06/09/2011
Author : Sathianarayanan.S
License: GPL2.0
Version: 1
=end
begin
 require 'rubygems'
 require 'nokogiri'
 require 'open-uri'
 require 'net/http'
 require 'uri'
 puts 'Note: TBUS script. "x" in result denotes high frequency bus...'
 print "Enter the city. enter \n '1' for chennai and \n '2' for bangalore \nchoice:"
 city = gets.chomp
 if city == "1"
   print "Searching chennai..."
 else
   print "Searching bangalore.."
 end
 case city
  when "1"
  page = Nokogiri::HTML(open("http://en.wikipedia.org/wiki/List_of_MTC_Chennai_bus_routes"))
  when "2"
  page = Nokogiri::HTML(open("http://en.wikipedia.org/wiki/List_of_Metropolitan_bus_routes_in_Bangalore"))
 end
 while true
 print "\nSource: "
 source = gets.chomp
 print 'Destination: '
 destination = gets.chomp
 source_up =  source.capitalize
 source_low = source.downcase
 destination_up =  destination.capitalize
 destination_low = destination.downcase
 result = page.search('table.wikitable tr')
   result.each do |nodes|
     if (nodes.to_s.include?(source_up) || nodes.to_s.include?(source_low)) && (nodes.to_s.include?(destination_up) || nodes.to_s.include?(destination_low))
       puts nodes.content
       puts '====================================='
     end
   end
 end
rescue Interrupt
 puts "\nQuitting.."
end

  Output: 

sathia@sathia27 ~/Desktop $ ruby tbus.rb
Enter the city. enter
‘1’ for chennai and
‘2’ for bangalore
choice:1
Searching chennai…
Source: villivakkam
Destination: adyar
47
Adyar
Villivakkam VIA T.NAGAR
x

=====================================
47B
Besant Nagar
Villivakkam Via Avvai Home, Adyar B.S,T.Nagar,Anna Nagar

=====================================

Source:

Posted in programs | Tagged , , , , , , , , , , , , , | 1 Comment

[Version:1] Easy Dictionary

Hi .

Easily browse for meaning of words from terminal, than searching for word in dictionary or searching in internet (dont waiting for word till whole page loads). This script scraps word form http://dictionary.reference.com .

Dependencies:

ruby, rubygems, mechanize(gem).

we can have multiple search or one way search

Eg.   dict.rb embattled

or run dict.rb and search for unlimitted words.

Note: It works with internet only.

#!/usr/bin/env ruby
=begin
Program name: Easy Dictionary
Date Written: 04/09/2011
Date Modified: 04/09/2011
Author : Sathianarayanan.S
License: GPL2.0
Version: 1.1
=end
begin
require 'rubygems'
require 'mechanize'

agent = Mechanize.new
agent.user_agent_alias = 'Mac Safari'
page = agent.get("http://dictionary.reference.com/")
puts 'Powered by Dictionary.com (dictionary.reference.com)'
puts "\n"
puts 'searching....'
puts "=========================================================================\n"
if ARGV[0]
  word = ARGV[0]
end
while true
        unless ARGV[0]
          print "Enter the word: "
          word = gets.chomp
	end
	form = page.forms.first
	form.q = word
	system("espeak #{word}")
	page = agent.submit form
	meanings = agent.page.search('.lunatext .body .luna-Ent')
	if meanings.empty?
	  puts 'No results'
	else
	  meanings.each do |meaning|
	    puts meaning.text
	  end
	end
        puts '=================================================================='
        if ARGV[0]
          break
        end
end
rescue SocketError
  puts 'Internet connection failed!!'
rescue Interrupt
  puts 'Quiting!!!'
end

Usage:

sathia@sathia27 ~/Desktop $ ruby dict.rb embattled
Powered by Dictionary.com (dictionary.reference.com)

searching....
=========================================================================
1.disposed or prepared for battle.
2.engaged in or beset by conflict or struggle.
1.to arrange in order of battle; prepare for battle; arm.
2.to fortify (a town, camp, etc.).
to furnish with battlements.
==================================================================
sathia@sathia27 ~/Desktop $

OR

sathia@sathia27 ~/Desktop $ ruby dict.rb
Powered by Dictionary.com (dictionary.reference.com)

searching....
=========================================================================
Enter the word: embattled
1.disposed or prepared for battle.
2.engaged in or beset by conflict or struggle.
1.to arrange in order of battle; prepare for battle; arm.
2.to fortify (a town, camp, etc.).
to furnish with battlements.
==================================================================
Enter the word:
Posted in programs | Tagged , , , , , , , , , , , | Leave a comment

Gplus script version 1.1

In previous post, when I run gplus script it will display

the stream from circle we mentioned in command

eg. ruby gplus.rb username password circle_name

In this version , It will prompt for username and password .. and it displays all circle names of

current user .. and we can see streams of any circle shown 🙂

 

Dependencies:

ruby, rubygems, mechanize(gem),  highline (gem for secure password)

Ruby code

=begin
Program name: Gplus script
Date Written: 16/08/2011
Date Modified: 17/08/2011
Author : Sathianarayanan.S
License: GPL2.0
Version: 1.1
=end
begin
require 'rubygems'
require 'mechanize'
require "highline/import"

print "Enter your username: "
username = gets.chomp
password = ask("Enter the password :" ) { |p| p.echo = "*" }
password = password.chomp

agent = Mechanize.new
agent.user_agent_alias = 'Mac Safari'
page = agent.get("https://www.google.com/accounts/ServiceLogin?service=oz&continue=https://plus.google.com/?gpcaz%3D94cd3e2c&ltmpl=es2st&hideNewAccountLink=1&hl=en-GB")
puts 'Logggig....'
puts "=========================================================================\n"
form = page.forms.first
form.Email = username
form.Passwd = password

page = agent.submit form
circles = agent.page.search('#content .c-j.a-nb-j.a-nb-Jh-j')

puts 'Streams:'
i = 1
circles.each do |circle|
  puts i.to_s+') '+circle
  i+=1
end
puts "=========================================================================\n"
while true
 print "Enter circle: "
 circle_name = gets.chomp

 page = agent.page.link_with(:text => circle_name).click

 streams = page.search('#contentPane div.sj')
 i = 1
 streams.each do |stream|
   if stream.text != ''
     puts i.to_s+') '+stream.search('span.kh').text+' shared:'
     puts stream.search('div.eo').text
   else
     puts  i.to_s+') '+'Video/photos...'
   end
   puts ''
   i+=1
 end
 puts "=========================================================================\n"
end

rescue SocketError
 puts 'Error in internet connection'
rescue NoMethodError
  puts 'Invalid username or password or circle'
rescue Interrupt
  puts "\n========================================================================="
  puts "\nQuiting...."
end
Posted in programs | Tagged , , , , , , , , , , , , , , , , | 3 Comments