From 8ed7a39b8624e2e30c71bf5069020de1b0062e40 Mon Sep 17 00:00:00 2001 From: Tejasvi Nareddy Date: Tue, 25 Dec 2018 13:14:39 -0500 Subject: [PATCH] Reformat file --- sherlock.py | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/sherlock.py b/sherlock.py index 79d8abec..482dce53 100644 --- a/sherlock.py +++ b/sherlock.py @@ -2,9 +2,10 @@ import requests import json import os + def write_to_file(url, fname): - with open(fname, "a") as f: - f.write(url+"\n") + with open(fname, "a") as f: + f.write(url + "\n") def main(): @@ -22,14 +23,17 @@ def main(): username = input("\033[92;1m[\033[37;1m?\033[92;1m]\033[92;1m Input Username: \033[0m") print() - fname = username+".txt" + fname = username + ".txt" if os.path.isfile(fname): - os.remove(fname) - print("\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Removing previous file:\033[1;37m {}\033[0m".format(fname)) - + os.remove(fname) + print( + "\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Removing previous file:\033[1;37m {}\033[0m".format(fname)) - print("\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Checking username\033[0m\033[1;37m {}\033[0m\033[1;92m on: \033[0m".format(username)) + print( + "\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Checking username\033[0m\033[1;37m {}\033[0m\033[1;92m on: " + "\033[0m".format( + username)) raw = open("data.json", "r") data = json.load(raw) @@ -43,38 +47,38 @@ def main(): for social_network in data: url = data.get(social_network).get("url").format(username) error_type = data.get(social_network).get("errorType") - r = requests.get(url, headers=headers) - + if error_type == "message": error = data.get(social_network).get("errorMsg") - + if not error in r.text: print("\033[37;1m[\033[92;1m+\033[37;1m]\033[92;1m {}:\033[0m".format(social_network), url) - write_to_file(url, fname) - + write_to_file(url, fname) + else: - print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".format(social_network)) - + print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".format(social_network)) + elif error_type == "status_code": - + if not r.status_code == 404: print("\033[37;1m[\033[92;1m+\033[37;1m]\033[92;1m {}:\033[0m".format(social_network), url) write_to_file(url, fname) - + else: - print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".format(social_network)) + print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".format(social_network)) elif error_type == "response_url": error = data.get(social_network).get("errorMsgInUrl") - + if not error in r.url: print("\033[37;1m[\033[92;1m+\033[37;1m]\033[92;1m {}:\033[0m".format(social_network), url) write_to_file(url, fname) else: - print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".format(social_network)) + print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".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")) + - print("\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Saved: \033[37;1m{}\033[0m".format(username+".txt")) - -main() \ No newline at end of file +main()