-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (55 loc) · 1.82 KB
/
index.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"use strict";
const request = require("request");
const parseString = require("xml2js").parseString;
const stripPrefix = require("xml2js").processors.stripPrefix;
const fs = require("fs");
const path = require("path");
////twit
const twit = require("twit");
const config = require("./config.js");
var registered = [];
var lastTitle = "";
var twitErab = "";
/////////////////twitter konfigurazioa
const Twitter = new twit(config);
//////// ea azkena.txt badagoen
const AZKENA_FILE = process.env.DB_PATH
? path.join(process.env.DB_PATH, "azkena.txt")
: "azkena.txt";
///////irakurri piztean azken titulua
var lastTitle = fs.readFileSync(AZKENA_FILE).toString();
/////////////
setInterval(() => {
console.log("setInterval begiratu berririk baden:");
request("http://etzi.pm/feed/", (err, res, body) => {
parseString(body, { tagNameProcessors: [stripPrefix] }, (err, result) => {
console.log("setIntervalItem: "+result.rss.channel[0].item[0]);
let newest = result.rss.channel[0].item[0];
if (lastTitle === newest.title[0]) {
console.log("Ez dago albiste berririk: " + lastTitle);
return;
}
//
fs.unlinkSync(AZKENA_FILE);
console.log('azkena gorde'+newest.title[0]);
fs.appendFileSync(AZKENA_FILE, newest.title[0]);
//
lastTitle = newest.title[0];
twitErab = newest.creator;
// twit
Twitter.post(
"statuses/update",
{
status: twitErab + " - " + lastTitle + ": " + newest.link + " #etziBot"
},
function(err, data, response) {
if (err) {
console.log("Error in tweeting azken posta");
} else {
console.log("Azken posta shown successfully");
}
}
);
});
});
}, 1000 * 60 * 10);