Edits history of script submission #17200 for ' Returns PNG weather map for given area and variable (meteosource)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Returns PNG weather map for given area and variable
     * ## PNG weather forecast maps for given area and variable
    
    ### Area specification
    There are two ways to specify geographical area you need for your map:
    1.
     */
    export async function main(
    	auth: RT.Meteosource,
    	variable: string | undefined,
    	datetime: string | undefined,
    	tile_x?: string | undefined,
    	tile_y?: string | undefined,
    	tile_zoom?: string | undefined,
    	min_lat?: string | undefined,
    	min_lon?: string | undefined,
    	max_lat?: string | undefined,
    	max_lon?: string | undefined,
    	key?: string | undefined
    ) {
    	const url = new URL(`https://www.meteosource.com/api/v1/${auth.tier}/map`)
    	for (const [k, v] of [
    		['tile_x', tile_x],
    		['tile_y', tile_y],
    		['tile_zoom', tile_zoom],
    		['min_lat', min_lat],
    		['min_lon', min_lon],
    		['max_lat', max_lat],
    		['max_lon', max_lon],
    		['variable', variable],
    		['datetime', datetime],
    		['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.text()
    }
    

    Submitted by hugo697 235 days ago