-
Notifications
You must be signed in to change notification settings - Fork 2
/
weather.js
35 lines (27 loc) · 1.1 KB
/
weather.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const fetch = require('node-fetch')
const APPID = '' // <-- Put your OpenWeatherMap appid here!
const URL_BASE = 'http://api.openweathermap.org/data/2.5/'
async function currentWeather (location) {
const response = await fetch(`${URL_BASE}weather?q=${location}&appid=${APPID}`)
const data = await response.json()
return data
}
async function weatherForecast (location) {
const response = await fetch(`${URL_BASE}forecast?q=${location}&appid=${APPID}`)
const data = await response.json()
return data
}
async function oneCallApi (latitude, longitude) {
const response = await fetch(`${URL_BASE}onecall?lat=${latitude}&lon=${longitude}&appid=${APPID}`)
const data = await response.json()
return data
}
currentWeather('Kolkata')
.then(data => console.log(data))
weatherForecast('Kolkata')
.then(data => console.log(data))
oneCallApi(55.68, 12.57)
.then(data => console.log(data))
def weather_onecall(lat: float = 55.68, lon: float = 12.57, appid: str = APPID) -> dict:
"""https://openweathermap.org/api/one-call-api"""
return requests.get(URL_BASE + "onecall", params=locals()).json()