-
-
Save HyperTHD/544b2900e612b5fbcd674931a4266f6a to your computer and use it in GitHub Desktop.
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 e836720..ef4dd83 100644 | |
--- a/README.md | |
+++ b/README.md | |
@@ -23,6 +23,11 @@ To see your output in a JSON format, type the following: | |
```urlChecker -j ``` | |
+This url machine function also allows you to check the telescope project and run this program using the 10 | |
+latest blog posts urls posted. Run telescope locally first, then, to check each url, type the following: | |
+ | |
+```urlChecker -t``` | |
+ | |
To run the program as written above, enter the following into your terminal | |
diff --git a/urlChecker.py b/urlChecker.py | |
index 89a1419..9cae0f8 100644 | |
--- a/urlChecker.py | |
+++ b/urlChecker.py | |
@@ -32,6 +32,20 @@ def checkFile(fileInput, isJson=False, ignore=None): | |
input.processFile() | |
+# checkTelescope function makes a request to "Telescope" to parse the 10 latest post urls | |
+# to check whether the urls are broken or not. Displays output based on -j argument | |
+# Params: inputFile, isJson | |
+# Return: void | |
+ | |
+def checkTelescope(fileInput=None, isJson=False): | |
+ if isJson: | |
+ input = urlAutomationMachine(fileInput, isJson) | |
+ input.processTelescope() | |
+ else: | |
+ input = urlAutomationMachine(fileInput) | |
+ input.processTelescope() | |
+ | |
+ | |
# Main function parses each line looking for urls to check and make requests | |
# to check whether the url is broken or not. Calls the appropriate check function | |
# based on the argument passed | |
@@ -44,16 +58,18 @@ def main(args): | |
try: | |
threading.Thread(target=checkFile(args.f, args.j, args.i)).start() | |
except: | |
- sys.stderr.write("No URLS are good, exiting") | |
+ sys.stderr.write("No urls are good, exiting") | |
sys.exit(1) | |
sys.exit(0) | |
elif (args.u): | |
try: | |
threading.Thread(target=checkURL(args.u, args.j)).start() | |
except: | |
- sys.stderr.write("No URLS are good, exiting") | |
+ sys.stderr.write("No urls are good, exiting") | |
sys.exit(1) | |
sys.exit(0) | |
+ elif (args.t): | |
+ threading.Thread(target=checkTelescope(args.t, args.j)).start() | |
elif (args.v): | |
print("URLAutomationMachine Ver 2.0") | |
else: | |
@@ -73,6 +89,7 @@ if __name__ == "__main__": | |
parse.add_argument('-u', help="The URL to check") | |
parse.add_argument('-j', action="store_true", help="Displays output in JSON format") | |
parse.add_argument('-i', help="Ignores any url that matches the argument") | |
+ parse.add_argument('-t', action='store_true', help='Will ignore the file given and instead check the 10 latest posts to telescope') | |
args = parse.parse_args() | |
main(args) | |
diff --git a/urlClass.py b/urlClass.py | |
index 62dbecd..0ae4359 100644 | |
--- a/urlClass.py | |
+++ b/urlClass.py | |
@@ -1,5 +1,6 @@ | |
import urllib3 | |
import re | |
+import json | |
from colorama import Fore, init | |
# Class urlAutomationMachine | |
@@ -9,7 +10,7 @@ from colorama import Fore, init | |
class urlAutomationMachine: | |
- def __init__(self, input, isJson=False, ignore=None): | |
+ def __init__(self, input=None, isJson=False, ignore=None): | |
self.input = input | |
self.listOfUrls = [] | |
self.isJson = isJson | |
@@ -60,3 +61,18 @@ class urlAutomationMachine: | |
print(Fore.RED + f"[FAILURE]: {url} fails automation. This url is broken unfortunately!") | |
else: | |
print(Fore.WHITE + f"[UNKNOWN] {url} gives off a warning. This url is fishy!") | |
+ | |
+ | |
+ | |
+ def processTelescope(self): | |
+ telescopeURL = 'http://localhost:3000/posts' # Local host telescope url to grab data locally | |
+ try: | |
+ posts = self.http.request('GET', telescopeURL) | |
+ posts = json.loads(posts.data) | |
+ for post in posts: | |
+ self.makeRequest(f"{telescopeURL}/{post['id']}") | |
+ except urllib3.exceptions.MaxRetryError as e: # At this point, the connection attempt timed out and therfore, the url cannot be reached, so in this case, we skip the url entirely. | |
+ print(str(e)) | |
+ | |
+ | |
+ | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment