Created
March 13, 2011 15:53
-
-
Save autch/868189 to your computer and use it in GitHub Desktop.
輪番停電PDFをMacのpreviewで選択→テキストエディタに貼り付け、そしてこのスクリプトに与える
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby1.8 | |
# create table rt ( | |
# id integer unsigned not null auto_increment primary key, | |
# pref char(32) not null, | |
# city char(32) not null, | |
# addr char(32) not null, | |
# rt_group integer not null, | |
# | |
# index(pref,city,addr,rt_group) | |
# ) auto_increment = 1; | |
$KCODE = 'u' | |
require 'mysql' | |
mysql = Mysql.new(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB) | |
mysql.query("SET CHARACTER SET utf8") | |
mysql.query("SET NAMES utf8") | |
stmt = mysql.prepare("INSERT IGNORE INTO rt (pref, city, addr, rt_group) VALUES (?, ?, ?, ?)") | |
begin | |
loop do | |
p = ARGF.gets | |
c = ARGF.gets | |
a = ARGF.gets | |
if /\d+/ =~ a then | |
g = a.to_i | |
a = "" | |
else | |
g = ARGF.gets.to_i | |
end | |
break unless(p && c && a && g) | |
stmt.execute(p, c, a, g) | |
end | |
ensure | |
stmt.close | |
mysql.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment