Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move dependent code inside with block #3

Closed
c3ho opened this issue Sep 25, 2020 · 0 comments
Closed

Move dependent code inside with block #3

c3ho opened this issue Sep 25, 2020 · 0 comments

Comments

@c3ho
Copy link

c3ho commented Sep 25, 2020

detectURL/detectURL.py

Lines 32 to 54 in 695ab05

with open(sys.argv[1]) as file:
for line in file:
url = re.findall('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', line)
if url:
urls += url
final_urls = list(dict.fromkeys(urls)) # Remove Duplicates
for link in final_urls:
try:
r = requests.get(link, timeout=1.5)
if r.status_code == 200:
print(Fore.GREEN + "GOOD - " + str(link))
r.raise_for_status()
except requests.exceptions.HTTPError as e:
status_code = e.response.status_code
if status_code == 400 or 404:
print(Fore.RED + "BAD - " + link)
else:
print(Fore.WHITE + "UNKNOWN - " + link)
except requests.exceptions.ConnectionError:
print(Fore.WHITE + "UNKNOWN - " + link)
except requests.exceptions.Timeout:
print(Fore.RED + "BAD - " + link)

Since everything is dependent on a file or the opening of a file, wouldn't it be better to move everything inside whether the file is opened? So anything from Line 37 onwards should be inside the Line 32 block

jongwon-jang pushed a commit that referenced this issue Sep 25, 2020
jongwon-jang added a commit that referenced this issue Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants