Skip to content

Instantly share code, notes, and snippets.

@kanemu
Created June 10, 2010 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanemu/433019 to your computer and use it in GitHub Desktop.
Save kanemu/433019 to your computer and use it in GitHub Desktop.
[groovy]郵便番号から住所を表示する(研修用サンプル)
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