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') \ .gsub(/jou/, 'jo') \ .gsub(/dou/, 'do') \ .sub(/tou/, 'to') \ .sub(/Shuu/, 'Shu') \ .sub(/Yousuke/, 'Yosuke') \ .sub(/Etou/, 'Eto') \ .sub(/Yuu/, 'Yu') 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] party = Uconv.euctou8(party) if party == '自民' then party = 'the Liberal Democratic Party (Japan)' elsif party == '民主' then party = 'the Democratic Party of Japan' elsif party == '公明' then party = 'the New Komeito Party' elsif party == '無所属' or party == '所属' then party = 'independent' 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

now = Time.now accessdate = "#{now.year}-#{sprintf("%02d", now.month)}-#{sprintf("%02d", now.day)}"

if party == 'independent' then member = ', an independent and member' else member = " of #{party}, a member" end

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