Published
Edited
Aug 11, 2021
Importers
Insert cell
Insert cell
Insert cell
Insert cell
pomber = getPombers()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
latestDate = covidAPI.latestDate()
Insert cell
globalCount = covidAPI.globalCount()
Insert cell
globalLatest = covidAPI.latest()
Insert cell
israel = await covidAPI.country('ISR')
Insert cell
latestIsrael = covidAPI.latest('ISR')
Insert cell
Object.entries(israel.result).sort(([a], [b]) => a < b ? 1 : -1)[0][1]
Insert cell
israelTodat = {
const getter = (date) => covidAPI.country('ISR', date).catch(() => false)
try {
const results = (await getter(yesterday)) || (await getter(beforeYesterday)) || (await getter(beforeBeforeYesterday))
return results
} catch (err) {
console.log('error #1:', err)
}
return []
}
Insert cell
// globalTodayYesterday = await (new Promise(() => covidAPI.globalTimeseries(beforeYesterday, yesterday)).catch(() => false))
Insert cell
// globalWeek = covidAPI.globalTimeseries(weekago, today)
Insert cell
today = moment(Date.now()).format(TIME_FORMAT)
Insert cell
yesterday = moment(Date.now()).subtract(1, 'day').format(TIME_FORMAT)
Insert cell
beforeYesterday = moment(Date.now()).subtract(2, 'day').format(TIME_FORMAT)
Insert cell
beforeBeforeYesterday = moment(Date.now()).subtract(3, 'day').format(TIME_FORMAT)
Insert cell
weekago = moment(Date.now()).subtract(1, 'week').format(TIME_FORMAT)
Insert cell
global = await covidAPI.global()
Insert cell
Insert cell
covidAPI = {
const URL = `https://covidapi.info/api/v1`
const get = async (...endpoint) => (await (await fetch(`${URL}/${endpoint.filter(e => !!e).join('/')}`)).json())
const getBody = async (...endpoint) => (await (await fetch(`${URL}/${endpoint.filter(e => !!e).join('/')}`)).text())
return {
// country('USA') — Country specific historic data
// country('USA', '2020-03-23') — Country specific data for a particular date
// country('2020-03-23', '2020-03-27') — Country specific time-series data
country: (country, dateStart = false, dateEnd = false) =>
get(...(!dateEnd
? ['country', country, dateStart]
: ['country', country, 'timeseries', dateStart, dateEnd]
)),
// global() — Latest Global Count
// global('2020-03-23') — Global count on a particular date
// global('2020-03-23', '2020-03-27') — Global count in a date range
global: (dateStart = false, dateEnd = false) =>
get('global', dateStart, dateEnd),
// globalTimeseries('2020-03-23', '2020-03-27') — Global Timeseries data in date range
globalTimeseries: (dateStart, dateEnd) =>
get('global', 'timeseries', dateStart, dateEnd),
// globalCount() — Global date-wise count
globalCount: () => get('global', 'count'),
// Date of last record entry for any country
latestDate: () => getBody('latest-date'),
// latest() — Latest count for all countries
// latest('USA') — Latest record for a country
latest: (country = false) => get(...(country ? ['country', country, 'latest'] : ['global', 'latest']))
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
TIME_FORMAT = 'YYYY-MM-DD'
Insert cell
md`# Dependencies`
Insert cell
Insert cell
moment = require('moment')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more