| Uutiset | Koodikirjasto | Wiki | Keskustelut | FAQ | Info |
fastwiki - rubyrane 17.06.06 19:55 kenties nopeampi tapa avata artikkeli wikipediasta
# fastwiki.rb - rane
# usage: ruby / rubyw fastwiki.rbw (rubyw only for windows)
# use of hotkey to run the script is highly recommended :)
# type the name or names of the article(s) you wish to be opened in firefox (or other browser that accepts URLs as arguments)
# separate multiple articles with comma. e.g. "foo,bar"
# ! -prefix in the article opens the article in secondary language
# changelog:
# 19.6.2006 v0.2 - gui - fixes the issue with scandinavian characters when using crappy windows terminal
# 17.6.2006 v0.1 - initial release
#variables
a = ["en", "fi"] # 'foo' opens english wikipedia article meanwhile '!foo' opens finnish
path_to_firefox = "path" # change to correct path IF your firefox isn't located in one of the paths below
# ----------------
require 'tk'
class Fastwiki
def initialize(a, path_to_firefox)
@a = a
@path_to_firefox = path_to_firefox
@text = TkVariable.new
root = TkRoot.new { title "fastwiki" }
top = TkFrame.new(root)
@entry = TkEntry.new(top, 'textvariable' => @text)
@entry.focus
@entry.pack
top.pack
root.bind("Key-Return") {
self.firefox
exit
}
end
protected
def firefox_path
fa = ['/usr/bin/firefox','c:\Program Files\Mozilla Firefox\firefox.exe']
fa.push(@path_to_firefox)
fa.each do |path|
if FileTest.exist?(path)
return path
end
end
end #method
def firefox
article = @text.value.gsub(/ /, '_').split(',')
cmd = self.firefox_path+' '
article.each do
|article|
if article =~ /[!]/ then cc = @a[1]
else cc = @a[0]
end
article = article.gsub(/^[!]/, '')
wikipedia_url = "http://#{cc}.wikipedia.org/wiki/"
cmd << wikipedia_url+article+' '
end
system(cmd)
end #method
end #class
Fastwiki.new(a,path_to_firefox)
Tk.mainlooprane 21:56 17.6.06 itselläni hotkey tämän skriptin ajoon on windows näppäin + Q, siihen sitten saakin helposti naputettua artikkelin :) Nyrhinen 08:29 19.6.06 Kylläpä nyt on tullut ranelta hyödyllisiä vinkkejä, peukku pystyyn tälle vaikken Rubystä niin perustakaan. \o editoitu: 19:11 2.12.06 rane 05:35 20.6.06 |
![]() Haku
|