Skip to content

Instantly share code, notes, and snippets.

@robinclart
Created April 16, 2020 08:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinclart/ef490fd1404341c8cd12297ef5048fd7 to your computer and use it in GitHub Desktop.
Save robinclart/ef490fd1404341c8cd12297ef5048fd7 to your computer and use it in GitHub Desktop.
Convert data from covid19 stats for Thailand into a tab separated list that can be imported into a spreasheet
require "excon"
require "json"
data = JSON.parse(Excon.get("https://covid19.th-stat.com/api/open/timeline").body)
timeline = data["Data"].reverse.take(60).map do |day|
[
day["Date"],
day["NewConfirmed"],
day["NewRecovered"],
day["NewHospitalized"],
day["Confirmed"],
day["Recovered"],
day["Hospitalized"],
day["Deaths"],
].join("\t")
end
puts ["Date", "NewConfirmed", "NewRecovered", "NewHospitalized", "Confirmed", "Recovered", "Hospitalized", "Deaths"].join("\t")
puts timeline.reverse.join("\n")
@robinclart
Copy link
Author

robinclart commented Apr 16, 2020

Use with

ruby convert-to-table.rb | pbcopy

Note: remove | pbcopy if not on a mac. And make sure to have excon installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment