Move response time for query into QueryResult() object.

pull/590/head
Christopher K. Hoadley 4 years ago
parent 2a8f97b609
commit c054712920

@ -31,7 +31,7 @@ class QueryResult():
Describes result of query about a given username. Describes result of query about a given username.
""" """
def __init__(self, status, context=None): def __init__(self, status, query_time=None, context=None):
"""Create Query Result Object. """Create Query Result Object.
Contains information about a specific method of detecting usernames on Contains information about a specific method of detecting usernames on
@ -41,6 +41,8 @@ class QueryResult():
self -- This object. self -- This object.
status -- Enumeration of type QueryStatus() indicating status -- Enumeration of type QueryStatus() indicating
the status of the query. the status of the query.
query_time -- Time (in seconds) required to perform query.
Default of None.
context -- String indicating any additional context context -- String indicating any additional context
about the query. For example, if there was about the query. For example, if there was
an error, this might indicate the type of an error, this might indicate the type of
@ -51,8 +53,9 @@ class QueryResult():
Nothing. Nothing.
""" """
self.status = status self.status = status
self.context = context self.query_time = query_time
self.context = context
return return

@ -280,7 +280,6 @@ def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False,
results_site["url_user"] = "" results_site["url_user"] = ""
results_site['http_status'] = "" results_site['http_status'] = ""
results_site['response_text'] = "" results_site['response_text'] = ""
results_site['response_time_s'] = ""
else: else:
# URL of user on site (if it exists) # URL of user on site (if it exists)
url = net_info["url"].format(username) url = net_info["url"].format(username)
@ -376,20 +375,26 @@ def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False,
response_text = "" response_text = ""
if error_text is not None: if error_text is not None:
result = QueryResult(QueryStatus.UNKNOWN, error_text) result = QueryResult(QueryStatus.UNKNOWN,
query_time=response_time,
context=error_text)
elif error_type == "message": elif error_type == "message":
error = net_info.get("errorMsg") error = net_info.get("errorMsg")
# Checks if the error message is in the HTML # Checks if the error message is in the HTML
if not error in r.text: if not error in r.text:
result = QueryResult(QueryStatus.CLAIMED) result = QueryResult(QueryStatus.CLAIMED,
query_time=response_time)
else: else:
result = QueryResult(QueryStatus.AVAILABLE) result = QueryResult(QueryStatus.AVAILABLE,
query_time=response_time)
elif error_type == "status_code": elif error_type == "status_code":
# Checks if the status code of the response is 2XX # Checks if the status code of the response is 2XX
if not r.status_code >= 300 or r.status_code < 200: if not r.status_code >= 300 or r.status_code < 200:
result = QueryResult(QueryStatus.CLAIMED) result = QueryResult(QueryStatus.CLAIMED,
query_time=response_time)
else: else:
result = QueryResult(QueryStatus.AVAILABLE) result = QueryResult(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
@ -397,9 +402,11 @@ def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False,
# 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(QueryStatus.CLAIMED) result = QueryResult(QueryStatus.CLAIMED,
query_time=response_time)
else: else:
result = QueryResult(QueryStatus.AVAILABLE) result = QueryResult(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 "
@ -430,7 +437,6 @@ def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False,
# Save results from request # Save results from request
results_site['http_status'] = http_status results_site['http_status'] = http_status
results_site['response_text'] = response_text results_site['response_text'] = response_text
results_site['response_time_s'] = response_time
# Add this site's results into final dictionary with all of the other results. # Add this site's results into final dictionary with all of the other results.
results_total[social_network] = results_site results_total[social_network] = results_site
@ -654,13 +660,16 @@ def main():
] ]
) )
for site in results: for site in results:
response_time_s = results[site]['status'].query_time
if response_time_s is None:
response_time_s = ""
writer.writerow([username, writer.writerow([username,
site, site,
results[site]['url_main'], results[site]['url_main'],
results[site]['url_user'], results[site]['url_user'],
str(results[site]['status'].status), str(results[site]['status'].status),
results[site]['http_status'], results[site]['http_status'],
results[site]['response_time_s'] response_time_s
] ]
) )

Loading…
Cancel
Save