Lab6: Add an argument to check links in Telescope posts

Lab 6 is about adding an argument to check links in Telescope's recent 10 posts to the link checker command-line tool named url-fi which I created. The instruction of lab 6 is the following:  https://github.com/Seneca-CDOT/topics-in-open-source-2020/wiki/lab-6

The website named Telescope is an open-source web server and client application for aggregating and presenting a timeline of Seneca's open-source blogs. The way of setting up the Telescope and the GitHub repository links are the following:
Telescope GitHub repository: https://github.com/Seneca-CDOT/telescope

After I set up the Telescope and can run it locally, I started improving my command-line tool by putting additional argument options. As way I can get the recent I used the way to get the recent Telescope 10 blogs is using the link "localhost:3000/posts" which gives the JSON format information about the link, I write some code to interact with the local Telescope server and get post links. There are representatively three parts I add my code to implement the feature.

First, I added const variable named telescopeUrl which is the link I can get the recent 10 Telecope blogs.
//telescope url
const telescopeUrl = "http://localhost:3000/posts";

Second, I created the function named checkTelescopePosts. It uses the variable named telescopeUrl to get the JSON file from the link. It checks all the links in the JSON file and displays the results of the URLs checking.
// Check telescope's recent 10 posts link
function checkTelescopePosts() {
    request(
        telescopeUrl
        , function (errresbody) {
            let postIds = JSON.parse(body);
            for (let i = 0i < postIds.lengthi++) {
                let postUrl = `${telescopeUrl}/${postIds[i].id}`;
                checkUrl(postUrl);

                if (sFlag) {
                    checkUrl(postUrl.replace(/^http/"https"));
                }
            }
        })
}

Third, in the for loop I created to check the arguments, I added checking 't' argument part. When the user runs the tool with the argument t, it goes to the function named checkTelescopPosts.
        if (arg.includes("t")) {
            tFlag = true;
            checkTelescopePosts();
        }

This is the output of my link checker when I run 'url-fi -t'.

There are additional coding parts I wrote to implement the feature such as creating t flag. You can check the detailed code changes looking at the gist I created for the lab6:  https://gist.github.com/hyunjiLeeTech/89f4f8b97bdd66c1e814b0fb7dc3d9c0

While I am working on the lab6, I realized it would be better to move my functions to the bottom and move the main functions to the top. So I created commits to improve the maintenance. Also, I added more comments about my code: 

The most difficult part of this lab was set up the Telescope. As the Telescope has some prerequisites such as Redis and Elasticsearch which I had not used before, I needed to install them and learn how to use docker, how to install Ubuntu. It was an interesting challenge but it takes the most time for my lab6. After I finish preparing the prerequisites, I ran the Telescope. Working with Telescope REST API itself was okay and modifying my link checker with the data from Telescope does not need lots of change. I just need to apply the way I've already written. I think my code is in good shape to accomplish and I feel I am ready to challenge a more complicated one.

Comments

Popular posts from this blog

Open Source Project: Lab2 (Pull Request)

Lab 8: Automated Testing and Continuous Integration

Release 0.3: Internal Project (Telescope)