ramda-cli:
curl -s https://gist.githubusercontent.com/jorinvo/7f19ce95a9a842956358/raw/e319340c2f6691f9cc8d8cc57ed532b5093e3619/data.json \ | ramda 'filter where name: (complement isNil), creditcard: (complement isNil)' 'map (x) -> x.name + ", " + x.creditcard' -o raw > `date +%Y%m%d.csv`
scala:
import java.io.{BufferedWriter, FileOutputStream, OutputStreamWriter} import java.text.SimpleDateFormat import java.util.Date import io.circe.generic.auto._ import io.circe.parser._ object Data extends App { case class CCInfo(name: Option[String], creditcard: Option[String]) val url = "https://gist.githubusercontent.com/jorinvo/7f19ce95a9a842956358/raw/e319340c2f6691f9cc8d8cc57ed532b5093e3619/data.json" val json = scala.io.Source.fromURL(url).mkString val infos = decode[List[CCInfo]](json).toOption.get val lines = infos.collect{case CCInfo(Some(name), Some(creditcard)) => s"$name, $creditcard"} Helper.writeToFile(lines, s"${Helper.formatDate("yyyyMMdd")}.csv") } object Helper { def writeToFile(lines: TraversableOnce[String], fileName: String): Unit = { val writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName))) for (x <- lines) { writer.write(x + "\n") } writer.close() } def formatDate(format: String, date: Date = new Date()) = new SimpleDateFormat(format).format(new Date()) }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
ramda-cli:
scala: