Skip to content

Commit 3fb6f82

Browse files
committedJun 9, 2020
Remove feeds that dont work, or repeatedly timeout
1 parent 42d35a5 commit 3fb6f82

File tree

6 files changed

+70
-205
lines changed

6 files changed

+70
-205
lines changed
 

‎.vscode/settings.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@
4343
"typescript.format.insertSpaceAfterKeywordsInControlFlowStatements": false,
4444
"typescript.tsc.autoDetect": "on",
4545
"typescript.validate.enable": true,
46-
"markdown.extension.toc.githubCompatibility": true
46+
"markdown.extension.toc.githubCompatibility": true,
47+
"editor.codeActionsOnSave": {
48+
"source.fixAll.eslint": true
49+
}
4750
}

‎feeds/process.ts

+53-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from "fs";
22
import * as path from "path";
33
import * as opmlToJSON from "opml-to-json";
44
import * as rimraf from "rimraf";
5-
5+
import { timeout } from "promise-timeout";
66
import * as Parser from "rss-parser";
77

88
import { OPML } from "./opml";
@@ -39,24 +39,64 @@ async function Process({ source, output }: { source: string; output: string }) {
3939
folder.children &&
4040
folder.children.map(async feed => {
4141
try {
42-
const url = new URL(feed.htmlurl);
42+
await timeout(
43+
new Promise(async (resolve, reject) => {
44+
try {
45+
const url = new URL(feed.htmlurl);
46+
47+
const items = await parser.parseURL(feed.xmlurl);
4348

44-
const items = await parser.parseURL(feed.xmlurl);
49+
await fs.mkdirSync(
50+
path.join(__dirname, output, url.hostname),
51+
{
52+
recursive: true,
53+
}
54+
);
4555

46-
await fs.mkdirSync(path.join(__dirname, output, url.hostname), {
47-
recursive: true,
48-
});
56+
await fs.writeFileSync(
57+
path.join(__dirname, output, url.hostname, "feed.json"),
58+
JSON.stringify({ ...feed, ...items }, null, 2),
59+
{ encoding: "utf8" }
60+
);
4961

50-
await fs.writeFileSync(
51-
path.join(__dirname, output, url.hostname, "feed.json"),
52-
JSON.stringify({ ...feed, ...items }, null, 2),
53-
{ encoding: "utf8" }
62+
resolve();
63+
} catch (err) {
64+
reject(err);
65+
}
66+
}),
67+
60000
5468
);
5569
return true;
5670
} catch (err) {
57-
// console.error(err);
58-
// If this blog continues to error, we'll remove it
59-
console.error("FAILED: ", feed.xmlurl);
71+
if (!err.toString().includes("429")) {
72+
console.error("FAILED: ", feed.xmlurl);
73+
74+
console.error(err);
75+
// If this blog continues to error, we'll remove it
76+
const opmlRaw = fs.readFileSync(path.join(__dirname, source));
77+
78+
const opmlLines = opmlRaw.toString().split("\n");
79+
80+
const opmlUpdate = opmlLines
81+
.map(line => {
82+
if (line.includes(feed.xmlurl)) {
83+
return;
84+
}
85+
86+
return line;
87+
})
88+
.filter(Boolean)
89+
.join("\n");
90+
91+
await fs.writeFileSync(
92+
path.join(__dirname, source),
93+
opmlUpdate,
94+
{
95+
encoding: "utf8",
96+
}
97+
);
98+
}
99+
60100
return true;
61101
}
62102
})

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"prettier": "^1.15.3",
6969
"react-scripts-ts": "3.1.0",
7070
"redbox-react": "^1.6.0",
71-
"rss-parser": "^3.7.2",
71+
"rss-parser": "^3.8.0",
7272
"spectacle-renderer": "^0.0.3",
7373
"ts-node": "^8.3.0",
7474
"typescript": "^3.3.3333",
@@ -132,6 +132,7 @@
132132
"opml-to-json": "^0.0.3",
133133
"prism-react-renderer": "^0.1.6",
134134
"prismjs": "^1.15.0",
135+
"promise-timeout": "^1.3.0",
135136
"prop-types": "^15.6.2",
136137
"react": "^16.8.6",
137138
"react-dom": "^16.8.6",

‎remove.txt

-82
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.