1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 11:39:36 +02:00

Created WeatherWidget

This commit is contained in:
unknown 2021-05-19 18:26:57 +02:00
parent 38f5d3b66a
commit e170f56a03
11 changed files with 462 additions and 57 deletions

View file

@ -3,21 +3,27 @@ const Weather = require('../models/Weather');
const axios = require('axios');
const getExternalWeather = async () => {
// Get API key from database
let secret = await Config.findOne({
where: { key: 'WEATHER_API_KEY' }
});
// Get config from database
const config = await Config.findAll();
// Find and check values
const secret = config.find(pair => pair.key === 'WEATHER_API_KEY');
const lat = config.find(pair => pair.key === 'lat');
const long = config.find(pair => pair.key === 'long');
if (!secret) {
console.log('API key was not found');
console.log('API key was not found. Weather updated failed');
return;
}
secret = secret.value;
if (!lat || !long) {
console.log('Location was not found. Weather updated failed');
return;
}
// Fetch data from external API
try {
const res = await axios.get(`http://api.weatherapi.com/v1/current.json?key=${secret}&q=52.229676,21.012229`);
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);