-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.cjs
30 lines (22 loc) · 848 Bytes
/
index.cjs
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
const utils = require('./utils/index.cjs');
const weatherApiKey = require('./secret/config');
/* MAIN FUNCTION */
async function main() {
// Variables
const locationUrl = 'http://ipinfo.io';
const weatherApiUrl = `http://api.openweathermap.org/data/2.5/weather?appid=${weatherApiKey}&q=`;
// Check Sites are Online
utils.checkConnection(['ipinfo.io', 'api.openweathermap.org']);
// Get Location Info
const locData = await utils.getData(locationUrl);
if(!locData) { console.warn("Error: Failed to get location."); utils.killMe(); };
// Get Weather Info
const weatherData = await utils.getData(weatherApiUrl+locData.city);
if(!weatherData) { console.warn("Error: Failed to get weather."); utils.killMe(); };
// Print Status
utils.reportWeather(weatherData);
// Quit
utils.killMe();
}
/* START AT MAIN */
main();