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

Some refactoring
This commit is contained in:
Yahya SayadArbabi 2022-04-06 20:35:02 +04:30 committed by GitHub
commit 03b70c9990
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 53 deletions

View file

@ -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)

View file

@ -200,10 +200,9 @@ 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]"
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:

View file

@ -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

View file

@ -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)