remove unnecessary files
This commit is contained in:
parent
1e76c60992
commit
faf9a61e2a
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -101,6 +101,4 @@ dist
|
|||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
data/articles.json
|
||||
.tern-port
|
96
indexvs.js
96
indexvs.js
|
@ -1,96 +0,0 @@
|
|||
const { login } = require("masto");
|
||||
const fs = require("fs");
|
||||
const Parser = require("rss-parser");
|
||||
const parser = new Parser();
|
||||
require("dotenv").config();
|
||||
|
||||
var rawArticles;
|
||||
if (!fs.existsSync("./data/articles.json")) {
|
||||
var rawArticles = JSON.stringify({ data: [] });
|
||||
fs.writeFileSync("./data/articles.json", rawArticles);
|
||||
} else {
|
||||
var rawArticles = fs.readFileSync("./data/articles.json");
|
||||
}
|
||||
let checkFromFile = JSON.parse(rawArticles);
|
||||
let checkedArticles = [];
|
||||
checkFromFile.data.forEach((data) => {
|
||||
checkedArticles.push(data);
|
||||
});
|
||||
|
||||
let articlesToBePosted = [];
|
||||
let newArticlesAmount = 0;
|
||||
|
||||
main().catch((e) => {
|
||||
throw e;
|
||||
});
|
||||
async function main() {
|
||||
console.log(
|
||||
`[${new Date().toUTCString()}] - [Mastodon] Logged in to Mastodon`
|
||||
);
|
||||
|
||||
checkForArticles();
|
||||
setInterval(function () {
|
||||
checkForArticles();
|
||||
}, 1000 * 60 * 10);
|
||||
}
|
||||
|
||||
async function checkForArticles() {
|
||||
let itemsProcessed = 0;
|
||||
console.log(
|
||||
`[${new Date().toUTCString()}] - [Verge RSS] Checking for new articles...`
|
||||
);
|
||||
let feed = await parser.parseURL("https://www.theverge.com/rss/index.xml");
|
||||
|
||||
feed.items.forEach((item, index, array) => {
|
||||
itemsProcessed++;
|
||||
|
||||
if (!checkedArticles.includes(item.id)) {
|
||||
newArticlesAmount++;
|
||||
articlesToBePosted.push(item);
|
||||
checkedArticles.push(item.id);
|
||||
}
|
||||
|
||||
if (itemsProcessed === array.length) return checkCallback();
|
||||
});
|
||||
}
|
||||
|
||||
async function checkCallback() {
|
||||
console.log(
|
||||
`[${new Date().toUTCString()}] - [Verge RSS] Done checking for new articles. Next update will be in 10 minutes.`
|
||||
);
|
||||
|
||||
if (checkedArticles.length > 6) {
|
||||
checkedArticles = checkedArticles.slice(
|
||||
0 + newArticlesAmount,
|
||||
6 + newArticlesAmount
|
||||
);
|
||||
}
|
||||
newArticlesAmount = 0;
|
||||
|
||||
let data = JSON.stringify({ data: checkedArticles });
|
||||
fs.writeFileSync("./data/articles.json", data);
|
||||
|
||||
await postArticles();
|
||||
}
|
||||
|
||||
async function postArticles() {
|
||||
if (articlesToBePosted.length > 0) {
|
||||
console.log(
|
||||
`[${new Date().toUTCString()}] - [Mastodon] Posting ${
|
||||
articlesToBePosted.length
|
||||
} new articles...`
|
||||
);
|
||||
|
||||
const masto = await login({
|
||||
url: "https://wuff.space",
|
||||
accessToken: process.env.ACCESS_TOKEN,
|
||||
});
|
||||
articlesToBePosted.forEach((item) => {
|
||||
masto.statuses.create({
|
||||
status: `${item.title} - ${item.link}`,
|
||||
visibility: "public",
|
||||
});
|
||||
});
|
||||
articlesToBePosted = [];
|
||||
}
|
||||
}
|
|
@ -12,7 +12,6 @@
|
|||
"dependencies": {
|
||||
"dotenv": "^16.0.3",
|
||||
"feedsub": "^0.7.8",
|
||||
"masto": "^4.4.1",
|
||||
"rss-parser": "^3.12.0"
|
||||
"masto": "^4.4.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"script": "./index.js",
|
||||
"watch": true,
|
||||
"ignore_watch": ["data/articles.json", "node_modules", ".git"],
|
||||
"ignore_watch": ["node_modules", ".git"],
|
||||
"watch_options": {
|
||||
"followSymlinks": false
|
||||
},
|
||||
|
|
28
yarn.lock
28
yarn.lock
|
@ -90,11 +90,6 @@ dotenv@^16.0.3:
|
|||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07"
|
||||
integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==
|
||||
|
||||
entities@^2.0.3:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55"
|
||||
integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==
|
||||
|
||||
eventemitter3@^4.0.7:
|
||||
version "4.0.7"
|
||||
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
|
||||
|
@ -247,15 +242,7 @@ proxy-from-env@^1.1.0:
|
|||
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
|
||||
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
|
||||
|
||||
rss-parser@^3.12.0:
|
||||
version "3.12.0"
|
||||
resolved "https://registry.yarnpkg.com/rss-parser/-/rss-parser-3.12.0.tgz#b8888699ea46304a74363fbd8144671b2997984c"
|
||||
integrity sha512-aqD3E8iavcCdkhVxNDIdg1nkBI17jgqF+9OqPS1orwNaOgySdpvq6B+DoONLhzjzwV8mWg37sb60e4bmLK117A==
|
||||
dependencies:
|
||||
entities "^2.0.3"
|
||||
xml2js "^0.4.19"
|
||||
|
||||
sax@>=0.6.0, sax@^1.2.4:
|
||||
sax@^1.2.4:
|
||||
version "1.2.4"
|
||||
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
|
||||
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
|
||||
|
@ -313,19 +300,6 @@ ws@^8.8.0:
|
|||
resolved "https://registry.yarnpkg.com/ws/-/ws-8.11.0.tgz#6a0d36b8edfd9f96d8b25683db2f8d7de6e8e143"
|
||||
integrity sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==
|
||||
|
||||
xml2js@^0.4.19:
|
||||
version "0.4.23"
|
||||
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.23.tgz#a0c69516752421eb2ac758ee4d4ccf58843eac66"
|
||||
integrity sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==
|
||||
dependencies:
|
||||
sax ">=0.6.0"
|
||||
xmlbuilder "~11.0.0"
|
||||
|
||||
xmlbuilder@~11.0.0:
|
||||
version "11.0.1"
|
||||
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3"
|
||||
integrity sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==
|
||||
|
||||
yallist@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
|
||||
|
|
Loading…
Reference in a new issue