Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inkel/covid19
https://github.com/inkel/covid19
covid-19 go
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/inkel/covid19
- Owner: inkel
- License: mit
- Created: 2020-03-27T18:01:48.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-01T18:49:50.000Z (almost 5 years ago)
- Last Synced: 2024-06-20T05:16:42.438Z (7 months ago)
- Topics: covid-19, go
- Language: Go
- Size: 10.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# covid19api.com Go SDK
This package provides an API and some example commands for interacting with the [Free API for Data on the Coronavirus COVID19](https://covid19api.com/).
This is a work in progress, so be wary of things broken or not performant enough.
## Installation
As simple as:
```
go get github.com/inkel/covid19/covid19api
```## Example
I've included an example `covid19` command that you can install and execute like follows:
```
$ go install github.com/inkel/covid19/cmd/covid19$ covid19
```The code of this command is:
```go
package mainimport (
"fmt"
"os"
"text/tabwriter"
"time""github.com/inkel/covid19/covid19api"
)func main() {
s, err := covid19api.GetSummary()
if err != nil {
fmt.Println("Cannot fetch summary from covid19api.com: %v", err)
os.Exit(1)
}showCountry := func(slug string) bool {
if len(os.Args) == 1 {
return true
}for _, s := range os.Args[1:] {
if s == slug {
return true
}
}return false
}fmt.Printf("COVID-19 Summary at %v (%v ago)\n", s.Date, time.Since(s.Date).Truncate(time.Second))
fmt.Println("You can filter by passing each country's slug you want to include in the output.")
fmt.Println("Format for cases is new/total.\n")w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', tabwriter.AlignRight)
fmt.Fprintln(w, "Country\tSlug\tConfirmed\tRecovered\tDeaths\t")
for _, c := range s.Countries {
if showCountry(c.Slug) {
fmt.Fprintf(w, "%s\t%s\t%d/%d\t%d/%d\t%d/%d\t\n", c.Country, c.Slug, c.NewConfirmed, c.TotalConfirmed, c.NewRecovered, c.TotalRecovered, c.NewDeaths, c.TotalDeaths)
}
}w.Flush()
}
```## License
See [LICENSE](LICENSE).