User:TakuyaMurata/Ja-politician.rb


 * 1) !/usr/bin/ruby


 * 1) The program is under GPL.

$KCODE = 'e'

require 'romkan.rb' require 'uconv' $:.push("/usr/local/lib/site_ruby/1.8") require 'suikyo/suikyo.rb'

def strip_down(s) s.gsub(/'/, '').gsub(/rou/, 'ro') end

def to_romaji_name(romaji) romaji = romaji[2, romaji.length - 4]

suikyo = Suikyo.new suikyo.table.loadfile("katakana-hiragana") (last, first) = romaji.split(/(?:#{"\xa1\xa1"}|\s)+/, 2) last = suikyo.convert(last) # kata -> hira first = suikyo.convert(first) # kata -> hira last = last.to_roma.capitalize first = first.to_roma.capitalize last = strip_down(last) first = strip_down(first) return [first, last] end

cite = $*[0] t = `curl -s #{cite}` t = Uconv.u8toeuc(Uconv.sjistou8(t)) t = t.split(/\[^<>]*\[\n\r\s]*/, 2)[1] (kanji, t) = t.split(/[\r\n]+/, 2) kanji.gsub!(/#{"\xa1\xa1"}+/, ' ') (romaji, t) = t.split(/[\r\n]+/, 2) romaji.strip! (first, last) = to_romaji_name(romaji)

t = t.split(/#{' '}\s*#{' '}/, 2)[1] (from, t) = t.split(/#{Uconv.u8toeuc('【生年')}/, 2) from.sub!(/.+[\r\n]+/, '') from.gsub!(/[\r\n]/, '') from.gsub!(/\s+/, ' ') from.gsub!(/#{"\xa1\xa1"}+/, ' ') from.strip! (l, t) = t.split(/\/, 2) l.sub!(/^[^0-9]*/, '') (birth_year, birth_month, birth_day) = l.strip.split(/[^0-9]+/) birth_month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][birth_month.to_i - 1] (l, t) = t.split(/\/, 2) l.strip! party = l[l.length - 4, 4] if Uconv.euctou8(party) == '自民' then party = 'the Liberal Democratic Party (Japan)' elsif Uconv.euctou8(party) == '民主' then party = 'the Democratic Party of Japan' elsif Uconv.euctou8(party) == '公明' then party = 'the New Komeito Party' end

t.index(/\"([^\"]+)\"/) link = $1

kanji = Uconv.euctou8(kanji) from = Uconv.euctou8(from) if birth_day == nil then birth = birth_year else birth_month.sub!(/^0/, '') birth_day.sub!(/^0/, '') birth = "#{birth_month} #{birth_day}, #{birth_year}" end

puts <<END
 * 1) {first} #{last} (#{kanji}) is a Japanese politician of #{party}, a member of the House of Representatives in the Diet (national legislature). A native of and graduate of  University, he was elected to the House of Representatives for the first time in 19.