mirror of
https://github.com/pawelmalak/flame.git
synced 2026-02-28 01:13:11 +08:00
Fixed bug with weather logging. Fixed bug with search bar shortcuts
This commit is contained in:
@@ -5,14 +5,6 @@ const loadConfig = require('./loadConfig');
|
||||
const getExternalWeather = async () => {
|
||||
const { WEATHER_API_KEY: secret, lat, long } = await loadConfig();
|
||||
|
||||
if (!secret) {
|
||||
throw new Error('API key was not found. Weather updated failed');
|
||||
}
|
||||
|
||||
if (!lat || !long) {
|
||||
throw new Error('Location was not found. Weather updated failed');
|
||||
}
|
||||
|
||||
// Fetch data from external API
|
||||
try {
|
||||
const res = await axios.get(
|
||||
|
||||
@@ -3,20 +3,33 @@ const getExternalWeather = require('./getExternalWeather');
|
||||
const clearWeatherData = require('./clearWeatherData');
|
||||
const Sockets = require('../Sockets');
|
||||
const Logger = require('./Logger');
|
||||
const loadConfig = require('./loadConfig');
|
||||
const logger = new Logger();
|
||||
|
||||
// Update weather data every 15 minutes
|
||||
const weatherJob = schedule.scheduleJob('updateWeather', '0 */15 * * * *', async () => {
|
||||
try {
|
||||
const weatherData = await getExternalWeather();
|
||||
logger.log('Weather updated');
|
||||
Sockets.getSocket('weather').socket.send(JSON.stringify(weatherData));
|
||||
} catch (err) {
|
||||
logger.log(err.message, 'ERROR');
|
||||
const weatherJob = schedule.scheduleJob(
|
||||
'updateWeather',
|
||||
'0 */15 * * * *',
|
||||
async () => {
|
||||
const { WEATHER_API_KEY: secret } = await loadConfig();
|
||||
|
||||
try {
|
||||
const weatherData = await getExternalWeather();
|
||||
logger.log('Weather updated');
|
||||
Sockets.getSocket('weather').socket.send(JSON.stringify(weatherData));
|
||||
} catch (err) {
|
||||
if (secret) {
|
||||
logger.log(err.message, 'ERROR');
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
// Clear old weather data every 4 hours
|
||||
const weatherCleanerJob = schedule.scheduleJob('clearWeather', '0 5 */4 * * *', async () => {
|
||||
clearWeatherData();
|
||||
})
|
||||
const weatherCleanerJob = schedule.scheduleJob(
|
||||
'clearWeather',
|
||||
'0 5 */4 * * *',
|
||||
async () => {
|
||||
clearWeatherData();
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user