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

@ -280,7 +280,6 @@ def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False,
results_site["url_user"] = ""
results_site['http_status'] = ""
results_site['response_text'] = ""
results_site['response_time_s'] = ""
else:
# URL of user on site (if it exists)
url = net_info["url"].format(username)
@ -376,20 +375,26 @@ def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False,
response_text = ""
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":
error = net_info.get("errorMsg")
# Checks if the error message is in the HTML
if not error in r.text:
result = QueryResult(QueryStatus.CLAIMED)
result = QueryResult(QueryStatus.CLAIMED,
query_time=response_time)
else:
result = QueryResult(QueryStatus.AVAILABLE)
result = QueryResult(QueryStatus.AVAILABLE,
query_time=response_time)
elif error_type == "status_code":
# Checks if the status code of the response is 2XX
if not r.status_code >= 300 or r.status_code < 200:
result = QueryResult(QueryStatus.CLAIMED)
result = QueryResult(QueryStatus.CLAIMED,
query_time=response_time)
else:
result = QueryResult(QueryStatus.AVAILABLE)
result = QueryResult(QueryStatus.AVAILABLE,
query_time=response_time)
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
@ -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
# forward to some odd redirect).
if 200 <= r.status_code < 300:
result = QueryResult(QueryStatus.CLAIMED)
result = QueryResult(QueryStatus.CLAIMED,
query_time=response_time)
else:
result = QueryResult(QueryStatus.AVAILABLE)
result = QueryResult(QueryStatus.AVAILABLE,
query_time=response_time)
else:
#It should be impossible to ever get here...
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
results_site['http_status'] = http_status
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.
results_total[social_network] = results_site
@ -654,13 +660,16 @@ def main():
]
)
for site in results:
response_time_s = results[site]['status'].query_time
if response_time_s is None:
response_time_s = ""
writer.writerow([username,
site,
results[site]['url_main'],
results[site]['url_user'],
str(results[site]['status'].status),
results[site]['http_status'],
results[site]['response_time_s']
response_time_s
]
)

Loading…
Cancel
Save