Merge pull request #1283 from MoMMde/#1283-conflicts-resolved

Some refactoring
pull/1293/head
Yahya SayadArbabi 3 years ago committed by GitHub
commit 03b70c9990
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,10 +20,8 @@ if __name__ == "__main__":
major = sys.version_info[0] major = sys.version_info[0]
minor = sys.version_info[1] minor = sys.version_info[1]
python_version = str(
sys.version_info[0])+"."+str(sys.version_info[1])+"."+str(sys.version_info[2])
if major != 3 or major == 3 and minor < 6: if major != 3 or major == 3 and minor < 6:
python_version = str(major) + "." + str(minor) + "." + str(sys.version_info[2])
print("Sherlock requires Python 3.6+\nYou are using Python %s, which is not supported by Sherlock" % (python_version)) print("Sherlock requires Python 3.6+\nYou are using Python %s, which is not supported by Sherlock" % (python_version))
sys.exit(1) sys.exit(1)

@ -200,9 +200,8 @@ class QueryNotifyPrint(QueryNotify):
""" """
self.result = result self.result = result
if self.verbose is False or self.result.query_time is None:
response_time_text = "" response_time_text = ""
else: if self.result.query_time is not None and self.verbose == True:
response_time_text = f" [{round(self.result.query_time * 1000)}ms]" response_time_text = f" [{round(self.result.query_time * 1000)}ms]"
# Output to the terminal is desired. # Output to the terminal is desired.

@ -353,13 +353,12 @@ def sherlock(username, site_data, query_notify,
except: except:
response_text = "" response_text = ""
query_status = QueryStatus.UNKNOWN
error_context = None
if error_text is not None: if error_text is not None:
result = QueryResult(username, error_context = error_text
social_network,
url,
QueryStatus.UNKNOWN,
query_time=response_time,
context=error_text)
elif error_type == "message": elif error_type == "message":
# error_flag True denotes no error found in the HTML # error_flag True denotes no error found in the HTML
# error_flag False denotes error found in the HTML # error_flag False denotes error found in the HTML
@ -382,38 +381,18 @@ def sherlock(username, site_data, query_notify,
error_flag = False error_flag = False
break break
if error_flag: if error_flag:
result = QueryResult(username, query_status = QueryStatus.CLAIMED
social_network,
url,
QueryStatus.CLAIMED,
query_time=response_time)
else: else:
result = QueryResult(username, query_status = QueryStatus.AVAILABLE
social_network,
url,
QueryStatus.AVAILABLE,
query_time=response_time)
elif error_type == "status_code": elif error_type == "status_code":
# Checks if the Status Code is equal to the optional "errorCode" given in 'data.json' # Checks if the Status Code is equal to the optional "errorCode" given in 'data.json'
if error_code == r.status_code: if error_code == r.status_code:
result = QueryResult(username, query_status = QueryStatus.AVAILABLE
social_network,
url,
QueryStatus.AVAILABLE,
query_time=response_time)
# Checks if the status code of the response is 2XX # Checks if the status code of the response is 2XX
elif not r.status_code >= 300 or r.status_code < 200: elif not r.status_code >= 300 or r.status_code < 200:
result = QueryResult(username, query_status = QueryStatus.CLAIMED
social_network,
url,
QueryStatus.CLAIMED,
query_time=response_time)
else: else:
result = QueryResult(username, query_status = QueryStatus.AVAILABLE
social_network,
url,
QueryStatus.AVAILABLE,
query_time=response_time)
elif error_type == "response_url": elif error_type == "response_url":
# For this detection method, we have turned off the redirect. # For this detection method, we have turned off the redirect.
# So, there is no need to check the response URL: it will always # So, there is no need to check the response URL: it will always
@ -421,23 +400,21 @@ def sherlock(username, site_data, query_notify,
# code indicates that the request was successful (i.e. no 404, or # code indicates that the request was successful (i.e. no 404, or
# forward to some odd redirect). # forward to some odd redirect).
if 200 <= r.status_code < 300: if 200 <= r.status_code < 300:
result = QueryResult(username, query_status = QueryStatus.CLAIMED
social_network,
url,
QueryStatus.CLAIMED,
query_time=response_time)
else: else:
result = QueryResult(username, query_status = QueryStatus.AVAILABLE
social_network,
url,
QueryStatus.AVAILABLE,
query_time=response_time)
else: else:
# It should be impossible to ever get here... # It should be impossible to ever get here...
raise ValueError(f"Unknown Error Type '{error_type}' for " raise ValueError(f"Unknown Error Type '{error_type}' for "
f"site '{social_network}'") f"site '{social_network}'")
# Notify caller about results of query. # Notify caller about results of query.
result = QueryResult(username=username,
site_name=social_network,
site_url_user=url,
status=query_status,
query_time=response_time,
context=error_context)
query_notify.update(result) query_notify.update(result)
# Save status of request # Save status of request

@ -114,10 +114,7 @@ class SitesInformation:
if not data_file_path.lower().endswith(".json"): if not data_file_path.lower().endswith(".json"):
raise FileNotFoundError(f"Incorrect JSON file extension for data file '{data_file_path}'.") raise FileNotFoundError(f"Incorrect JSON file extension for data file '{data_file_path}'.")
if ( if data_file_path.lower().startswith("http"):
data_file_path[:7].lower() == "http://"
or data_file_path[:8].lower() == "https://"
):
# Reference is to a URL. # Reference is to a URL.
try: try:
response = requests.get(url=data_file_path) response = requests.get(url=data_file_path)

Loading…
Cancel
Save