//native
/**
* Returns weather data for a single location and given day in the past
* ## Actual weather data for a single location and day in the past
The output contains actual weather data for each day up to 20 years in the past, and long-term statistics of selected weather variables aggregated over 40 years.
*/
export async function main(
auth: RT.Meteosource,
date: string | undefined,
place_id?: string | undefined,
lat?: string | undefined,
lon?: string | undefined,
timezone?: string | undefined,
units?: 'auto' | 'metric' | 'us' | 'uk' | 'ca' | undefined,
language?: 'cs' | 'en' | 'de' | 'es' | 'fr' | 'pl' | 'pt' | undefined,
key?: string | undefined
) {
const url = new URL(`https://www.meteosource.com/api/v1/${auth.tier}/time_machine`)
for (const [k, v] of [
['place_id', place_id],
['lat', lat],
['lon', lon],
['date', date],
['timezone', timezone],
['units', units],
['language', language],
['key', key]
]) {
if (v !== undefined && v !== '') {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
'X-API-Key': auth.apiKey
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago