Created
June 10, 2010 13:46
-
-
Save kanemu/433019 to your computer and use it in GitHub Desktop.
[groovy]郵便番号から住所を表示する(研修用サンプル)
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
import au.com.bytecode.opencsv.* | |
@Grab(group='net.sf.opencsv', module='opencsv', version='2.1') | |
//「ゆうびんホームページ」から落としたcsvを同階層に置く | |
def text = new File('ken_all.csv').getText('MS932') | |
def reader = new CSVReader(new StringReader(text)) | |
def bangoMap = [:] | |
for(;;) { | |
String[] csv=reader.readNext() | |
if(!csv) break | |
bangoMap[csv[2]] = csv[6]+' '+csv[7]+' '+csv[8] | |
} | |
println '> Please input the ZIP code.' | |
def br = new BufferedReader(new InputStreamReader(System.in)) | |
for(;;) { | |
String str = br.readLine() | |
if (str == 'exit' || str == ''){ | |
println '> good bye.' | |
break | |
} | |
println bangoMap[str]? '> '+ bangoMap[str]:'> The address is not found.' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment