Skip to content

Instantly share code, notes, and snippets.

@TDDR

TDDR/lab6.diff Secret

Created November 2, 2020 19:12
Show Gist options
  • Save TDDR/a23c4a71c70cc1aca7d4ca93d689b1bf to your computer and use it in GitHub Desktop.
Save TDDR/a23c4a71c70cc1aca7d4ca93d689b1bf to your computer and use it in GitHub Desktop.
Lab 6 changes
diff --git a/CheckThatLink/checkThatLink.py b/CheckThatLink/checkThatLink.py
index af1fe97..d9a777e 100644
--- a/CheckThatLink/checkThatLink.py
+++ b/CheckThatLink/checkThatLink.py
@@ -12,7 +12,7 @@ if __name__ =="__main__":
argParser.add_argument(
'-v','--version',
action='version',
- version='%(prog)s 0.1'
+ version='%(prog)s 0.5'
)
argParser.add_argument(
'-s', '--secureHttp',
@@ -31,7 +31,7 @@ if __name__ =="__main__":
argParser.add_argument(
'-a', '--all',
action='store_true',
- help="Flag to display all links (defualt behaviour)",
+ help="Flag to display all links (default behavior)",
required=False
)
argParser.add_argument(
@@ -53,6 +53,11 @@ if __name__ =="__main__":
default='',
help='file of URL patterns to be ignored.'
)
+ argParser.add_argument(
+ '-t', '--telescope',
+ action='store_true',
+ help='Will ignore the file given and instead check the 10 latest posts to telescope'
+ )
args = argParser.parse_args()
checkFile(args)
\ No newline at end of file
diff --git a/CheckThatLink/src/checkFile.py b/CheckThatLink/src/checkFile.py
index 38cd76c..04612da 100644
--- a/CheckThatLink/src/checkFile.py
+++ b/CheckThatLink/src/checkFile.py
@@ -2,8 +2,8 @@
import urllib3
import codecs
+import json
import re
-import sys
from src.colourText import colourText
from src.parseURL import re_weburl
@@ -17,6 +17,7 @@ class checkFile:
self.good = args.good
self.bad = args.bad
self.ignoreFile = args.ignoreFile
+ self.telescope = args.telescope
self.style = colourText()
self.timeout = urllib3.Timeout(connect=2.5, read=2.5,)
@@ -29,6 +30,9 @@ class checkFile:
try:
if self.ignoreFile:
self.getIgnoreList(self.ignoreFile)
+
+ if self.telescope:
+ self.makeFileFromTelescope()
self.checkThatFile()
except Exception as e:
@@ -68,7 +72,9 @@ class checkFile:
url = re_weburl.search(line)
if(url):
- url = url.group(0)
+ url = url.group(0)
+ elif re.match('http://localhost:', line):
+ url = line
return url
@@ -115,8 +121,21 @@ class checkFile:
raise ValueError('\nInvalid file format for --ignore. Lines must start with "#", "http://", or "https://" only.')
except FileNotFoundError as e:
raise
-
+ # Overwrites the file given with data from Telescope posts
+ def makeFileFromTelescope(self):
+ self.fileToCheck.close()
+ self.fileToCheck = None
+ self.fileToCheck = []
+
+ baseURL = 'http://localhost:3000/posts/'
+
+ posts = self.manager.request('GET', baseURL)
+ posts = json.loads(posts.data.decode('utf-8'))
+
+ for post in posts:
+ self.fileToCheck.append(f'{baseURL}{post["id"]}')
+
def printAll(self):
for line in self.allLinks:
if(line["status"] == "???"):
@@ -135,6 +154,7 @@ class checkFile:
print(f'{self.jsonLinks}')
+
def printGoodResults(self):
for line in self.allLinks:
if(line["status"] == "???"):
@@ -153,6 +173,7 @@ class checkFile:
self.jsonLinks.append({"url":line["url"], "status": line["status"]})
print(f'{self.jsonLinks}')
+
def printBadResults(self):
for line in self.allLinks:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment