Lua wrapper for the coronavirus-tracker-api.
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. :)
> 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 = { ... }
}
}
}
The easiest way is to install it via luarocks.
luarocks install lua-covid-data
- lua <= 5.3
- lua-curl
- lua-dkjson
- or lua-cjson == 2.1.0-1
Set to true
if the timelines should be displayed by default. Defaults to false
.
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' }
.
The default data source. Defaults to 'jhu'
.
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/'
.
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)
.
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 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 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 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 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
gambiarra is needed to run the tests.
lua spec/covid-data_spec.lua