-
Notifications
You must be signed in to change notification settings - Fork 0
/
getWeather.js
42 lines (36 loc) · 1003 Bytes
/
getWeather.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
36
37
38
39
40
41
42
// https://weather.gc.ca/rss/city/qc-147_e.xml
// https://weather.gc.ca/city/pages/qc-147_metric_e.html
// const city = "qc-147";
// const lang = "e";
// const url = `https://weather.gc.ca/rss/city/${city}_${lang}.xml`;
/*
{
type: "Current Conditions",
condition: "Partly Cloudy",
temperature: "18.4°C",
pressureTendency: "102.0 kPa falling",
humidity: "61 %",
}
*/
import meteoWeather from "./meteo-weather/index.js";
async function getWeather() {
const options = {
lang: "en",
city: "qc-147",
};
const response = await meteoWeather(options);
const current = response.entries.filter(
(entry) => entry.type === "Current Conditions"
)[0];
const temp = current.temperature.replace("°C", "");
const rain = current.condition.toLowerCase().includes("rain") ? true : false;
return {
rain,
temp: parseFloat(temp),
};
}
async function main() {
const weather = await getWeather();
console.log(weather);
}
main().catch((error) => console.error(error));