Skip to content

Instantly share code, notes, and snippets.

@tanishiking
Created December 4, 2022 10:48
Show Gist options
  • Save tanishiking/9d76c3e423e4279198dd179d75127b2a to your computer and use it in GitHub Desktop.
Save tanishiking/9d76c3e423e4279198dd179d75127b2a to your computer and use it in GitHub Desktop.
#!/usr/bin/env -S scala-cli shebang --quiet
//> using lib "com.softwaremill.sttp.client3::core:3.8.3"
//> using lib "com.lihaoyi::os-lib:0.8.1"
//> using lib "com.mitchtalmadge:ascii-data:1.4.0"
//> using lib "com.lihaoyi::ujson:2.0.0"
// 147.47 ┤ ╭╮ ╭──╮ ╭─╮
// 146.52 ┤ ╭╯╰─╮ │ │╭─╯ ╰╮ ╭─╮╭──╮
// 145.56 ┤ │ ╰──╯ ╰╯ ╰╮│ ╰╯ │ ╭──╮╭─╮
// 144.60 ┤ ╭─╮╭─╮ ╭──╯ ╰╯ ╰╮ ╭─╮╭╯ ╰╯ ╰────╮
// 143.64 ┤ ╭─╯ ╰╯ │╭╮╭╮╭─╮ ╭─╮ ╭╯ ╰─╯ ╰╯ ╰──╮
// 142.68 ┤ │ ╰╯╰╯╰╯ │ │ │ ╭╯ ╰╮
// 141.72 ┤╭╯ ╰╮ ╭────╯ ╰─────╯ ╰──
// 140.76 ┤│ │ │
// 139.80 ┼╯ ╰╮ ╭╯
// 138.85 ┤ ╰────╯
import ujson._
import sttp.client3._
import com.mitchtalmadge.asciidata.graph.ASCIIGraph
import java.time._
val secret = "xxx"
val endDate = if (args.length > 1) LocalDate.parse(args(1)) else LocalDate.now()
val startDate = endDate.minus(Period.ofDays(90))
val client = SimpleHttpClient()
val response = client
.send(
basicRequest
.header("apikey", secret)
.get(
uri"https://api.apilayer.com/exchangerates_data/timeseries?start_date=${startDate}&end_date=${endDate}&base=EUR&symbols=JPY"
)
)
val responseBody =
response.body.getOrElse(throw new Exception("Service not responding"))
val data = ujson.read(responseBody)
val values =
data("rates").obj.toSeq.sortBy(_._1).map((_, value) => value("JPY").num)
println(ASCIIGraph.fromSeries(values.toArray).plot())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment