/lua-covid-data

Lua wrapper for the coronavirus-tracker-api. Mirror of

Primary LanguageLuaMIT LicenseMIT

Build Status

lua-covid-data

Lua wrapper for the coronavirus-tracker-api.

Warning

I am not a programmer, so here's a warning: This code was written in an exploratory way. If you encounter problems, see something wrong or something was implemented in a weird way, I would be happy if you tell me about it or create a pull request. Thank you. :)

Example

> covid_data = require('covid-data')
> covid_data.get_latest()
{
  latest = {
    confirmed = 242708,
    deaths = 9867,
    recovered = 0
  }
}
> covid_data.get_by_location_code('de', true)
{
  latest = { ... },
  locations = {
    {
      id = 120,
      country = 'Germany',
      ...,
      timelines = { ... }
    }
  }
}

Documentation

Installation

The easiest way is to install it via luarocks.

luarocks install lua-covid-data

Dependencies

Options

covid_data.timelines

Set to true if the timelines should be displayed by default. Defaults to false.

covid_data.sources

Table with available data sources at the time of writing this. The source parameter of the functions is checked agains this table and chooses the default if the given source is not in this table. If the API should support other sources in the future, they can be quickly added here without having to modify the module code. Defaults to { jhu = 'jhu', csbs = 'csbs' }.

covid_data.source

The default data source. Defaults to 'jhu'.

covid_data.api_url

The API URL coronavirus tracker API. Change it if you run your own instance of the tracker API. Defaults to 'https://coronavirus-tracker-api.herokuapp.com/v2/'.

covid_data.useragent

The useragent string for the request. Change it if you want to use another one. Defaults to 'lua-covid-data/$version libcurl/$version (https://codeberg.org/imo/lua-covid-data).

Functions

get_sources()

Get available data sources.

Returns:

(table | false) data | false in case of error
(string) error message
(string) in case of error the raw data (eg. the body)

See: Sources Endpoint

get_latest([source='jhu'])

Get latest total data.

Parameter:

  • source: (string) the data source [default: 'jhu']

Returns:

(table | false) data | false in case of error
(string) error message
(string) in case of error the raw data (eg. the body)

See: Latest Endpoint

get_locations([timelines=0[, source='jhu']])

Get latest data per location.

Parameter:

  • timelines: (boolean) set to true if you want timelines in the data [default: 0]
  • source: (string) the data source [default: 'jhu']

Returns:

(table | false) data | false in case of error
(string) error message
(string) in case of error the raw data (eg. the body)

See: Locations Endpoint

get_by_location_code(country_code[,timelines=0[, source='jhu']])

Get latest data for a specific location specified by a country code.

Parameter:

  • country_code: (string) an alpha-2 country_code
  • timelines: (boolean) set to true if you want timelines in the data [default: 0]
  • source: (string) the data source [default: 'jhu']

Returns:

(table | false) data | false in case of error
(string) error message
(string) in case of error the raw data (eg. the body)

Raises: Error if country_code is missing or not a string

See: Locations Endpoint

get_by_location_id(id[,timelines=0[, source='jhu']])

Get latest data for a specific location specified by id.

Parameter:

  • id: (number) location id
  • timelines: (boolean) set to true if you want timelines in the data [default: 0]
  • source: (string) the data source [default: 'jhu']

Returns:

(table | false) data | false in case of error
(string) error message
(string) in case of error the raw data (eg. the body)

Raises: Error if id is missing or not a number

See: Locations Endpoint

Tests

gambiarra is needed to run the tests.

lua spec/covid-data_spec.lua