Skip to content

Instantly share code, notes, and snippets.

@tuesd4y
Created April 2, 2020 13:42
Show Gist options
  • Save tuesd4y/f174f5e027f7d2dcd612c6dd80537857 to your computer and use it in GitHub Desktop.
Save tuesd4y/f174f5e027f7d2dcd612c6dd80537857 to your computer and use it in GitHub Desktop.
transform ippodo.co.jp tea order into a machine-readable csv file
502612 Kumpu 100g Bag(Green Tea) Gift Wrapping?:No 2000
408612 Hekiun 100g Bag(Green Tea) Gift Wrapping?:No 1400
602102 Kuki Hojicha (Roasted Stems) 100g Bag(Green Tea) Gift Wrapping?:No 500
606612 Gokujo Genmaicha 100g Bag(Green Tea) Gift Wrapping?:No 450
133624 Horai-no-mukashi 20g Can(Green Tea) Gift Wrapping?:No 1100
182024 Shoin-no-mukashi 20g Can(Green Tea) Gift Wrapping?:No 1500
103644 Sayaka-no-mukashi 40g Can (Green Tea) Gift Wrapping?:No 2200
643402 Mugicha (Barley Tea) 400g Bag Gift Wrapping?:No 380
642152 Uji-Shimizu 150g Bag(Green Tea) Gift Wrapping?:No 300
136623 Enishi-no-shiro 20g Box(Green Tea) Gift Wrapping?:No 600
135624 Kimmo-no-mukashi 20g Can(Green Tea) Gift Wrapping?:No 700
133624 Horai-no-mukashi 20g Can(Green Tea) Gift Wrapping?:No 1100
import java.io.File
var i = 0
// copy the items-part from your order confirmation email in here
val order = """
502612
Kumpu 100g Bag(Green Tea)
Gift Wrapping?:No
\2,000 * 1
408612
Hekiun 100g Bag(Green Tea)
Gift Wrapping?:No
\1,400 * 1
602102
Kuki Hojicha (Roasted Stems) 100g Bag(Green Tea)
Gift Wrapping?:No
\500 * 1
606612
Gokujo Genmaicha 100g Bag(Green Tea)
Gift Wrapping?:No
\450 * 1
133624
Horai-no-mukashi 20g Can(Green Tea)
Gift Wrapping?:No
\1,100 * 1
182024
Shoin-no-mukashi 20g Can(Green Tea)
Gift Wrapping?:No
\1,500 * 1
103644
Sayaka-no-mukashi 40g Can (Green Tea)
Gift Wrapping?:No
\2,200 * 1
643402
Mugicha (Barley Tea) 400g Bag
Gift Wrapping?:No
\380 * 1
642152
Uji-Shimizu 150g Bag(Green Tea)
Gift Wrapping?:No
\300 * 1
136623
Enishi-no-shiro 20g Box(Green Tea)
Gift Wrapping?:No
\600 * 1
135624
Kimmo-no-mukashi 20g Can(Green Tea)
Gift Wrapping?:No
\700 * 1
133624
Horai-no-mukashi 20g Can(Green Tea)
Gift Wrapping?:No
\1,100 * 1
"""
// caveat: this only works when the quantity of each item is only 1, since we just drop everything after the * sign
val csv = order.trimIndent().lines().filter { it.isNotBlank() }
.map { it.replace(Regex("( \\* .*|\\\\|,)"), "") }
.groupBy { i++ / 4 }
.values
.joinToString("\n") {
it.joinToString()
}
val file = File("/Users/dev/Desktop/order.csv")
file.writeText(csv)
println(file.absoluteFile)
println(csv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment