Kirjautuminen

Haku

Tehtävät

Keskustelu: Koodit: fastwiki

rane_ [18.06.2006 01:50:20]

#

kenties nopeampi tapa avata artikkeli wikipediasta
kieli: ruby

skriptan säännölliseen käyttöön suosittelen pikanäppäintä

# fastwiki.rb - rane
# 17.6.2006
# usage: ruby fastwiki.rb
# 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

# 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
# ----------------
fa = ['/usr/bin/firefox','c:\Program Files\Mozilla Firefox\firefox.exe']
fa.push(path_to_firefox)
fa.each do |path|
  if FileTest.exist?(path)
    @firefox_path = path
    break
  end
end

puts "Wikipedia article:"
article = gets.chomp.gsub(/ /, '_').split(',')

cmd = @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)

Vastaus

Aihe on jo aika vanha, joten et voi enää vastata siihen.

Tietoa sivustosta