Skip to content

Commit

Permalink
Use dict.items() to simplify interaction with dict (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Dec 30, 2018
1 parent 03c41ee commit 60555ee
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sherlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def sherlock(username, verbose=False, tor=False, unique_tor=False):
results_total = {}

# First create futures for all requests. This allows for the requests to run in parallel
for social_network in data:
for social_network, net_info in data.items():

# Results from analysis of this specific site
results_site = {}
Expand All @@ -119,21 +119,21 @@ def sherlock(username, verbose=False, tor=False, unique_tor=False):
results_site['url_main'] = data.get(social_network).get("urlMain")

# Don't make request if username is invalid for the site
regex_check = data.get(social_network).get("regexCheck")
regex_check = net_info["regexCheck"]
if regex_check and re.search(regex_check, username) is None:
# No need to do the check at the site: this user name is not allowed.
print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Illegal Username Format For This Site!".format(social_network))
results_site["exists"] = "illegal"
else:
# URL of user on site (if it exists)
url = data.get(social_network).get("url").format(username)
url = net_info["url"].format(username)
results_site["url_user"] = url

# This future starts running the request in a new thread, doesn't block the main thread
future = session.get(url=url, headers=headers)

# Store future in data for access later
data.get(social_network)["request_future"] = future
net_info["request_future"] = future

# Reset identify for tor (if needed)
if unique_tor:
Expand All @@ -156,14 +156,14 @@ def sherlock(username, verbose=False, tor=False, unique_tor=False):
continue

# Get the expected error type
error_type = data.get(social_network).get("errorType")
error_type = net_info["errorType"]

# Default data in case there are any failures in doing a request.
http_status = "?"
response_text = ""

# Retrieve future and ensure it has finished
future = data.get(social_network).get("request_future")
future = net_info["request_future"]
r, error_type = get_response(request_future=future,
error_type=error_type,
social_network=social_network,
Expand All @@ -180,7 +180,7 @@ def sherlock(username, verbose=False, tor=False, unique_tor=False):
pass

if error_type == "message":
error = data.get(social_network).get("errorMsg")
error = net_info["errorMsg"]
# Checks if the error message is in the HTML
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)
Expand All @@ -201,7 +201,7 @@ def sherlock(username, verbose=False, tor=False, unique_tor=False):
exists = "no"

elif error_type == "response_url":
error = data.get(social_network).get("errorUrl")
error = net_info["errorUrl"]
# Checks if the redirect url is the same as the one defined in data.json
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)
Expand Down

0 comments on commit 60555ee

Please sign in to comment.