Answer the question
In order to leave comments, you need to log in
Timer in vk status node js?
Please help me add a timer until a certain date, currently there are:
{Hours}, {Minutes}, {Seconds}, {Day}, {Month}, {Year}, {Weather}
const fetch = require('node-fetch');
const request = require('request');
phrases = {
Hours() {
let date = new Date();
return date.getHours();
},
Minutes() {
let date = new Date();
return date.getMinutes();
},
Seconds() {
let date = new Date();
return date.getSeconds();
},
Day() {
let date = new Date();
return date.getDate();
},
Month() {
let date = new Date();
return date.getMonth();
},
Year() {
let date = new Date();
return date.getFullYear();
},
async Weather() {
let result = await fetch(`http://api.openweathermap.org/data/2.5/weather?q=Moscow,ru&appid=bf6c4e247bbd41fefe259d192b3d3c67&units=metric`);
result = await result.json();
return result.main.temp;
}
};
module.exports = ({
handleTemplate: async template => {
for (i in phrases) {
if (i == 'Weather') {
template = template.replace(RegExp(`{${i}}`, 'g'), await phrases[i]());
} else {
template = template.replace(RegExp(`{${i}}`, 'g'), phrases[i]());
}
}
return template;
}
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question