mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 03:29:37 +02:00
Update bookmark. Changes to CSS. Changes to WeatherJob
This commit is contained in:
parent
519b6d0746
commit
96aa1f7d69
11 changed files with 165 additions and 36 deletions
40
utils/Logger.js
Normal file
40
utils/Logger.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
const fs = require('fs');
|
||||
|
||||
class Logger {
|
||||
constructor() {
|
||||
this.logFileHandler();
|
||||
}
|
||||
|
||||
logFileHandler() {
|
||||
if (!fs.existsSync('./flame.log')) {
|
||||
fs.writeFileSync('./flame.log', '');
|
||||
} else {
|
||||
console.log('file exists');
|
||||
}
|
||||
}
|
||||
|
||||
writeLog(logMsg, logType) {
|
||||
|
||||
}
|
||||
|
||||
generateLog(logMsg, logType) {
|
||||
const now = new Date();
|
||||
const date = `${this.parseNumber(now.getDate())}-${this.parseNumber(now.getMonth() + 1)}-${now.getFullYear()}`;
|
||||
const time = `${this.parseNumber(now.getHours())}:${this.parseNumber(now.getMinutes())}:${this.parseNumber(now.getSeconds())}.${now.getMilliseconds()}`;
|
||||
const log = `[${date} ${time}]: ${logType} ${logMsg}`;
|
||||
return log;
|
||||
// const timestamp = new Date().toISOString();
|
||||
}
|
||||
|
||||
parseNumber(number) {
|
||||
if (number > 9) {
|
||||
return number;
|
||||
} else {
|
||||
return `0${number}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(logger.generateLog('testMsg', 'INFO'));
|
||||
|
||||
module.exports = new Logger();
|
|
@ -30,7 +30,7 @@ const getExternalWeather = async () => {
|
|||
|
||||
// Save weather data
|
||||
const cursor = res.data.current;
|
||||
await Weather.create({
|
||||
const weatherData = await Weather.create({
|
||||
externalLastUpdate: cursor.last_updated,
|
||||
tempC: cursor.temp_c,
|
||||
tempF: cursor.temp_f,
|
||||
|
@ -38,10 +38,9 @@ const getExternalWeather = async () => {
|
|||
conditionText: cursor.condition.text,
|
||||
conditionCode: cursor.condition.code
|
||||
});
|
||||
return weatherData;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
console.log('External API request failed');
|
||||
return;
|
||||
throw new Error('External API request failed');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,10 +4,10 @@ const Sockets = require('../Sockets');
|
|||
|
||||
const weatherJob = schedule.scheduleJob('updateWeather', '0 */15 * * * *', async () => {
|
||||
try {
|
||||
await getExternalWeather();
|
||||
const weatherData = await getExternalWeather();
|
||||
console.log('weather updated');
|
||||
Sockets.getSocket('weather').socket.send('weather updated');
|
||||
Sockets.getSocket('weather').socket.send(JSON.stringify(weatherData));
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
console.log(err.message);
|
||||
}
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue