Last active
November 6, 2020 04:02
-
-
Save hyunjiLeeTech/89f4f8b97bdd66c1e814b0fb7dc3d9c0 to your computer and use it in GitHub Desktop.
Lab 6 (Add link check for Telescope posts) Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/README.md b/README.md | |
index 233d2cf..c3f661d 100644 | |
--- a/README.md | |
+++ b/README.md | |
@@ -31,6 +31,9 @@ For example, if you write 'https://www.google.com" in the text file (ignore-urls | |
### Checks all the files in a directory path (Argument -r) | |
When you enter -r argument, this tool recursively map test all the files in the directory path (You must enter path not file name). | |
+### Check links in Telescope posts (Argument -t) | |
+When you enter -t argument, this tool checks the recent 10 posts in Telescopes. The post links are from local server (localhost:3000/posts) | |
+ | |
### Helping option | |
When you enter -h argument, this tool prints out the usage of this tool. | |
diff --git a/index.js b/index.js | |
index 46f0eba..06b724d 100644 | |
--- a/index.js | |
+++ b/index.js | |
@@ -12,11 +12,15 @@ const goodRegex = /\-\-good/; | |
const badRegex = /\-\-bad/; | |
const allRegex = /\-\-all/; | |
+//telescope url | |
+const telescopeUrl = "http://localhost:3000/posts"; | |
+ | |
// flags | |
let statusFlag = 1; // 1: all, 2: good, 3: bad | |
let sFlag = false; // check -s argument. true: -s exists, false: -s not exist | |
let rFlag = false; // check -r argument. true: -r exists, false: -r not exist | |
let iFlag = false; // check -i argument. true: -i exists, false: -i not exist | |
+let tFlag = false; | |
// others | |
let ignoredLink = []; | |
@@ -31,6 +35,7 @@ function CliHelpMsg() { | |
console.log("-h : display the usage of this tool") | |
console.log("-r : do the test for all files in the following directory") | |
console.log("-i : ignore the links on the ignore file. The ignore file should have at lease one url link") | |
+ console.log("-t : check the website named Telescope's recent 10 post links") | |
console.log("\n----------------------------------------------------------") | |
console.log("-------------------------Example--------------------------\n") | |
console.log("Usage : url-fi -v [FILENAME]") | |
@@ -38,6 +43,7 @@ function CliHelpMsg() { | |
console.log("Usage : url-fi -h [FILENAME]") | |
console.log("Usage : url-fi -r [DIRECTORY_PATH]") | |
console.log("Usage : url-fi -i [IGNORE_URL_LIST_FILE] [FILENAME]") | |
+ console.log("Usage : url-fi -t") | |
console.log("\n----------------------------------------------------------") | |
console.log("----------------------------------------------------------") | |
} | |
@@ -106,10 +112,16 @@ for (let i = 2; i < process.argv.length; i++) { | |
if (arg.includes("i")) { | |
iFlag = true; | |
} | |
+ | |
if (arg.includes("r")) { | |
rFlag = true; | |
findFilesInDir(process.argv[3]) | |
} | |
+ | |
+ if (arg.includes("t")) { | |
+ tFlag = true; | |
+ checkTelescopePosts(); | |
+ } | |
} | |
if (arg.match(goodRegex)) { | |
@@ -204,3 +216,19 @@ function checkUrl(url) { | |
} | |
}) | |
} | |
+ | |
+function checkTelescopePosts() { | |
+ request( | |
+ telescopeUrl | |
+ , function (err, res, body) { | |
+ let postIds = JSON.parse(body); | |
+ for (let i = 0; i < postIds.length; i++) { | |
+ let postUrl = `${telescopeUrl}/${postIds[i].id}`; | |
+ checkUrl(postUrl); | |
+ | |
+ if (sFlag) { | |
+ checkUrl(postUrl.replace(/^http/, "https")); | |
+ } | |
+ } | |
+ }) | |
+} | |
\ No newline at end of file | |
(END) | |
if (arg.match(goodRegex)) { | |
@@ -204,3 +216,19 @@ function checkUrl(url) { | |
} | |
}) | |
} | |
+ | |
+function checkTelescopePosts() { | |
+ request( | |
+ telescopeUrl | |
+ , function (err, res, body) { | |
+ let postIds = JSON.parse(body); | |
+ for (let i = 0; i < postIds.length; i++) { | |
+ let postUrl = `${telescopeUrl}/${postIds[i].id}`; | |
+ checkUrl(postUrl); | |
+ | |
+ if (sFlag) { | |
+ checkUrl(postUrl.replace(/^http/, "https")); | |
+ } | |
+ } | |
+ }) | |
+} | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment