startpage-engine/ext/owapi.js

42 lines
1.6 KiB
JavaScript

const axios = require("axios");
const config = require("../config.json");
exports.extract = (city, m, cb) => {
if (typeof m == "function") {
cb = m;
m = config.defaults["open-weather-measure"];
} else if (typeof m == "undefined") {
return null;
}
axios({
url: `https://openweathermap.org/data/2.5/weather?id=${city}&appid=439d4b804bc8187953eb36d2a8c26a02`,
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Referer": `https://openweathermap.org/city/${city}`,
"Upgrade-Insecure-Requests": "1",
"DNT": "1"
}
}).then(function(resp) {
axios({
url: `https://openweathermap.org/data/2.5/onecall?lat=${resp.data.coord.lat}&lon=${resp.data.coord.lon}&units=${m}&appid=439d4b804bc8187953eb36d2a8c26a02`,
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Referer": `https://openweathermap.org/city/${city}`,
"Upgrade-Insecure-Requests": "1",
"DNT": "1"
}
}).then(function(resp) {
cb(null, resp.data);
}).catch(function(err) {
cb(err, null);
})
}).catch(function(err) {
cb(err, null);
})
}