-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
28 lines (24 loc) · 813 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var cron = require('node-cron');
require('dotenv').config()
const { Bot } = require("grammy")
const bot = new Bot(process.env.Bot_token)
const rss = require('./src/rss');
const news = require('./src/news');
cron.schedule('* * * * *', () => {
console.log("Start Checking at " + new Date());
rss().then(data => {
// console.log(JSON.stringify(data, null, 4));
let items = data.data[0].item
items.forEach(e => {
let id = e.id[0]
let title = e.title[0]
let link = e.link[0]
if(!news.IsExist(id)){
bot.api.sendMessage('-1001307080127', title + "\n" + link).then(()=> {
news.addNews(id)
console.log("Post one : " + id);
})
}
});
})
});