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

Error handling #1

Merged
merged 5 commits into from
Dec 26, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add argparse. Styling in error messages
  • Loading branch information
shijuleon committed Dec 26, 2018
commit 7f65018746566c0067f96b18661d327cb786d2fd
36 changes: 29 additions & 7 deletions sherlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
import sys
import argparse

def write_to_file(url, fname):
with open(fname, "a") as f:
Expand All @@ -13,16 +14,16 @@ def make_request(url, headers, error_type):
if r.status_code:
return r, error_type
except requests.exceptions.HTTPError as errh:
print ("HTTP Error: ", errh)
print ("\033[37;1m[\033[91;1m-\033[37;1m]\033[91;1m HTTP Error:\033[93;1m", errh)
except requests.exceptions.ConnectionError as errc:
print ("Error Connecting: ", errc)
print ("\033[37;1m[\033[91;1m-\033[37;1m]\033[91;1m Error Connecting:\033[93;1m", errc)
except requests.exceptions.Timeout as errt:
print ("Timeout Error: ", errt)
print ("\033[37;1m[\033[91;1m-\033[37;1m]\033[91;1m Timeout Error:\033[93;1m", errt)
except requests.exceptions.RequestException as err:
print ("Unknown error: ", err)
print ("\033[37;1m[\033[91;1m-\033[37;1m]\033[91;1m Unknown error:\033[93;1m", err)
return None, ""

def main():
def sherlock(username):
# Not sure why, but the banner messes up if i put into one print function
print(" .\"\"\"-.")
print(" / \\")
Expand Down Expand Up @@ -96,5 +97,26 @@ def main():
print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Error!".format(social_network))

print("\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Saved: \033[37;1m{}\033[0m".format(username+".txt"))

main()


class ArgumentParserError(Exception): pass

class ArgumentParser(argparse.ArgumentParser):
def error(self, message):
print(" .\"\"\"-.")
print(" / \\")
print("\033[37;1m ____ _ _ _ | _..--'-.")
print("\033[37;1m/ ___|| |__ ___ _ __| | ___ ___| |__ >.`__.-\"\"\;\"`")
print("\033[37;1m\___ \| '_ \ / _ \ '__| |/ _ \ / __| |/ / / /( ^\\")
print("\033[37;1m ___) | | | | __/ | | | (_) | (__| < '-`) =|-.")
print("\033[37;1m|____/|_| |_|\___|_| |_|\___/ \___|_|\_\ /`--.'--' \ .-.")
print("\033[37;1m .'`-._ `.\ | J /")
print("\033[37;1m / `--.| \__/\033[0m")
self.print_usage(sys.stderr)

parser = ArgumentParser()
parser.add_argument('username', help='check services with given username')

args = parser.parse_args()
if args.username:
sherlock(args.username)