1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 03:29:37 +02:00

WeatherWidget temp unit. WeatherSettings update on change

This commit is contained in:
unknown 2021-06-07 12:17:10 +02:00
parent 08c769b630
commit d2e6ebae4f
8 changed files with 68 additions and 24 deletions

View file

@ -12,22 +12,17 @@ const getExternalWeather = async () => {
const long = config.find(pair => pair.key === 'long');
if (!secret) {
console.log('API key was not found. Weather updated failed');
return;
throw new Error('API key was not found. Weather updated failed');
}
if (!lat || !long) {
console.log('Location was not found. Weather updated failed');
return;
throw new Error('Location was not found. Weather updated failed');
}
// Fetch data from external API
try {
const res = await axios.get(`http://api.weatherapi.com/v1/current.json?key=${secret.value}&q=${lat.value},${long.value}`);
// For dev
// console.log(res.data);
// Save weather data
const cursor = res.data.current;
const weatherData = await Weather.create({
@ -35,6 +30,7 @@ const getExternalWeather = async () => {
tempC: cursor.temp_c,
tempF: cursor.temp_f,
isDay: cursor.is_day,
cloud: cursor.cloud,
conditionText: cursor.condition.text,
conditionCode: cursor.condition.code
});