#!/usr/bin/env ruby require 'rubygems' #Include the FireWatir file. require 'firewatir' #include the FireWatir Module. include FireWatir require "festivaltts4r" require 'optparse' class CatArguments < Hash def initialize(args) super() self[:site]= 'skid.org.in/' opts = OptionParser.new do |opts| opts.banner = "Usage: #$0 [options]" opts.on('-l', '--local', 'to use localhost:3000') do self[:site] = 'localhost:3000/' end opts.on_tail('-h', '--help', 'display this help and exit') do puts opts exit end end opts.parse!(args) end end def go_to (f,st) apps ||= ['modules'] cap ||= apps[0] puts "current app: #{cap} going to #{st}" f.goto(st) page_text=f.text if page_text =~ /say:"(.+)"/ speak=$1 speak.to_speech end t=f.table(:id,/content/) r=t.rows.first apps=[] r.each do |cell| m=cell.to_s apps << m unless m.empty? end aindex=apps.index(cap) || 0 p apps # p "aindex at loading #{aindex}" [Time.now,apps] end arguments = CatArguments.new(ARGV) site=arguments[:site] puts "use the key u for up, d for down, n for next module" puts "p for previous module. s for select, b for backspace" puts " Ctrl-C to end" begin apps=ARGV if apps.empty? apps=["modules"] end puts "running applications: #{apps.join(";")}" aindex=0 system('stty raw -echo') buttons=["up","backspace","down","select"] increment={'n' => 1, 'p' => -1} p ff=Firefox.new t,apps=go_to(ff,"http://#{site}#{apps[aindex]}/first_time") # loop until Ctrl-C pressed ch=STDIN.getc while ch != 3 inchar= ch.chr puts inchar if command=buttons.find{|c| c =~ /^#{inchar}/} t,apps=go_to(ff, "http://#{site}#{apps[aindex]}/#{command}") elsif inc=increment[inchar] aindex=(aindex+inc) % apps.size t,apps = go_to(ff, "http://#{site}#{apps[aindex]}/first_time") end ch=STDIN.getc end ensure system('stty -raw echo') ff.close unless ff.nil? end