mirror of
https://github.com/sherlock-project/sherlock
synced 2024-11-15 08:47:08 +00:00
Merge pull request #1283 from MoMMde/#1283-conflicts-resolved
Some refactoring
This commit is contained in:
commit
03b70c9990
4 changed files with 24 additions and 53 deletions
|
@ -20,10 +20,8 @@ if __name__ == "__main__":
|
|||
major = sys.version_info[0]
|
||||
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:
|
||||
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))
|
||||
sys.exit(1)
|
||||
|
||||
|
|
|
@ -200,11 +200,10 @@ class QueryNotifyPrint(QueryNotify):
|
|||
"""
|
||||
self.result = result
|
||||
|
||||
if self.verbose is False or self.result.query_time is None:
|
||||
response_time_text = ""
|
||||
else:
|
||||
response_time_text = f" [{round(self.result.query_time * 1000)} ms]"
|
||||
|
||||
response_time_text = ""
|
||||
if self.result.query_time is not None and self.verbose == True:
|
||||
response_time_text = f" [{round(self.result.query_time * 1000)}ms]"
|
||||
|
||||
# Output to the terminal is desired.
|
||||
if result.status == QueryStatus.CLAIMED:
|
||||
print(Style.BRIGHT + Fore.WHITE + "[" +
|
||||
|
|
|
@ -353,13 +353,12 @@ def sherlock(username, site_data, query_notify,
|
|||
except:
|
||||
response_text = ""
|
||||
|
||||
query_status = QueryStatus.UNKNOWN
|
||||
error_context = None
|
||||
|
||||
if error_text is not None:
|
||||
result = QueryResult(username,
|
||||
social_network,
|
||||
url,
|
||||
QueryStatus.UNKNOWN,
|
||||
query_time=response_time,
|
||||
context=error_text)
|
||||
error_context = error_text
|
||||
|
||||
elif error_type == "message":
|
||||
# error_flag True denotes no 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
|
||||
break
|
||||
if error_flag:
|
||||
result = QueryResult(username,
|
||||
social_network,
|
||||
url,
|
||||
QueryStatus.CLAIMED,
|
||||
query_time=response_time)
|
||||
query_status = QueryStatus.CLAIMED
|
||||
else:
|
||||
result = QueryResult(username,
|
||||
social_network,
|
||||
url,
|
||||
QueryStatus.AVAILABLE,
|
||||
query_time=response_time)
|
||||
query_status = QueryStatus.AVAILABLE
|
||||
elif error_type == "status_code":
|
||||
# Checks if the Status Code is equal to the optional "errorCode" given in 'data.json'
|
||||
if error_code == r.status_code:
|
||||
result = QueryResult(username,
|
||||
social_network,
|
||||
url,
|
||||
QueryStatus.AVAILABLE,
|
||||
query_time=response_time)
|
||||
query_status = QueryStatus.AVAILABLE
|
||||
# Checks if the status code of the response is 2XX
|
||||
elif not r.status_code >= 300 or r.status_code < 200:
|
||||
result = QueryResult(username,
|
||||
social_network,
|
||||
url,
|
||||
QueryStatus.CLAIMED,
|
||||
query_time=response_time)
|
||||
query_status = QueryStatus.CLAIMED
|
||||
else:
|
||||
result = QueryResult(username,
|
||||
social_network,
|
||||
url,
|
||||
QueryStatus.AVAILABLE,
|
||||
query_time=response_time)
|
||||
query_status = QueryStatus.AVAILABLE
|
||||
elif error_type == "response_url":
|
||||
# For this detection method, we have turned off the redirect.
|
||||
# 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
|
||||
# forward to some odd redirect).
|
||||
if 200 <= r.status_code < 300:
|
||||
result = QueryResult(username,
|
||||
social_network,
|
||||
url,
|
||||
QueryStatus.CLAIMED,
|
||||
query_time=response_time)
|
||||
query_status = QueryStatus.CLAIMED
|
||||
else:
|
||||
result = QueryResult(username,
|
||||
social_network,
|
||||
url,
|
||||
QueryStatus.AVAILABLE,
|
||||
query_time=response_time)
|
||||
query_status = QueryStatus.AVAILABLE
|
||||
else:
|
||||
# It should be impossible to ever get here...
|
||||
raise ValueError(f"Unknown Error Type '{error_type}' for "
|
||||
f"site '{social_network}'")
|
||||
|
||||
# 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)
|
||||
|
||||
# Save status of request
|
||||
|
|
|
@ -114,10 +114,7 @@ class SitesInformation:
|
|||
if not data_file_path.lower().endswith(".json"):
|
||||
raise FileNotFoundError(f"Incorrect JSON file extension for data file '{data_file_path}'.")
|
||||
|
||||
if (
|
||||
data_file_path[:7].lower() == "http://"
|
||||
or data_file_path[:8].lower() == "https://"
|
||||
):
|
||||
if data_file_path.lower().startswith("http"):
|
||||
# Reference is to a URL.
|
||||
try:
|
||||
response = requests.get(url=data_file_path)
|
||||
|
|
Loading…
Reference in a new issue