Merge pull request #1686 from sherlock-project/code-clean-up

Cleaned code to suite flake8's specifications
pull/1687/head
Siddharth Dushantha 1 year ago committed by GitHub
commit 5eb05ce265
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,7 +6,10 @@ results of queries.
from result import QueryStatus from result import QueryStatus
from colorama import Fore, Style from colorama import Fore, Style
import webbrowser import webbrowser
globvar = 0 # global variable to count the number of results.
# Global variable to count the number of results.
globvar = 0
class QueryNotify: class QueryNotify:
"""Query Notify Object. """Query Notify Object.
@ -53,7 +56,7 @@ class QueryNotify:
Nothing. Nothing.
""" """
# return # return
def update(self, result): def update(self, result):
"""Notify Update. """Notify Update.
@ -102,7 +105,8 @@ class QueryNotify:
Return Value: Return Value:
Nicely formatted string to get information about this object. Nicely formatted string to get information about this object.
""" """
return str(self.result) return str(self.result)
class QueryNotifyPrint(QueryNotify): class QueryNotifyPrint(QueryNotify):
"""Query Notify Print Object. """Query Notify Print Object.
@ -134,7 +138,7 @@ class QueryNotifyPrint(QueryNotify):
self.browse = browse self.browse = browse
return return
def start(self, message): def start(self, message):
"""Notify Start. """Notify Start.
@ -161,32 +165,6 @@ class QueryNotifyPrint(QueryNotify):
return return
def finish(self, message="The processing has been finished."):
"""Notify Start.
Will print the last line to the standard output.
Keyword Arguments:
self -- This object.
message -- The last phrase.
Return Value:
Nothing.
"""
title = "End"
print('\r') # An empty line between last line of main output and last line(more clear output)
print(Style.BRIGHT + Fore.GREEN + "[" +
Fore.YELLOW + "!" +
Fore.GREEN + f"] {title}" +
Fore.GREEN + ": " +
Fore.WHITE + f" {message}" )
# An empty line between first line and the result(more clear output)
# return
def countResults(self): def countResults(self):
"""This function counts the number of results. Every time the function is called, """This function counts the number of results. Every time the function is called,
the number of results is increasing. the number of results is increasing.
@ -200,7 +178,7 @@ class QueryNotifyPrint(QueryNotify):
global globvar global globvar
globvar += 1 globvar += 1
return globvar return globvar
def update(self, result): def update(self, result):
"""Notify Update. """Notify Update.
@ -217,9 +195,9 @@ class QueryNotifyPrint(QueryNotify):
self.result = result self.result = result
response_time_text = "" response_time_text = ""
if self.result.query_time is not None and self.verbose == True: if self.result.query_time is not None and self.verbose is 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.
if result.status == QueryStatus.CLAIMED: if result.status == QueryStatus.CLAIMED:
self.countResults() self.countResults()
@ -230,9 +208,9 @@ class QueryNotifyPrint(QueryNotify):
Fore.GREEN + Fore.GREEN +
f" {self.result.site_name}: " + f" {self.result.site_name}: " +
Style.RESET_ALL + Style.RESET_ALL +
f"{self.result.site_url_user}") f"{self.result.site_url_user}")
if self.browse: if self.browse:
webbrowser.open(self.result.site_url_user,2) webbrowser.open(self.result.site_url_user, 2)
elif result.status == QueryStatus.AVAILABLE: elif result.status == QueryStatus.AVAILABLE:
if self.print_all: if self.print_all:
@ -250,7 +228,7 @@ class QueryNotifyPrint(QueryNotify):
Fore.WHITE + "]" + Fore.WHITE + "]" +
Fore.GREEN + f" {self.result.site_name}:" + Fore.GREEN + f" {self.result.site_name}:" +
Fore.RED + f" {self.result.context}" + Fore.RED + f" {self.result.context}" +
Fore.YELLOW + f" ") Fore.YELLOW + " ")
elif result.status == QueryStatus.ILLEGAL: elif result.status == QueryStatus.ILLEGAL:
if self.print_all: if self.print_all:
@ -268,7 +246,7 @@ class QueryNotifyPrint(QueryNotify):
) )
return return
def finish(self, message="The processing has been finished."): def finish(self, message="The processing has been finished."):
"""Notify Start. """Notify Start.
Will print the last line to the standard output. Will print the last line to the standard output.
@ -285,18 +263,17 @@ class QueryNotifyPrint(QueryNotify):
print(Style.BRIGHT + Fore.GREEN + "[" + print(Style.BRIGHT + Fore.GREEN + "[" +
Fore.YELLOW + "*" + Fore.YELLOW + "*" +
Fore.GREEN + f"] {title}" + Fore.GREEN + f"] {title}" +
Fore.WHITE + f" {NumberOfResults}" ) Fore.WHITE + f" {NumberOfResults}")
title = "End" title = "End"
print('\r') # An empty line between last line of main output and last line(more clear output) # An empty line between last line of main output and last line(more clear output)
print('\r')
print(Style.BRIGHT + Fore.GREEN + "[" + print(Style.BRIGHT + Fore.GREEN + "[" +
Fore.YELLOW + "!" + Fore.YELLOW + "!" +
Fore.GREEN + f"] {title}" + Fore.GREEN + f"] {title}" +
Fore.GREEN + ": " + Fore.GREEN + ": " +
Fore.WHITE + f" {message}" ) Fore.WHITE + f" {message}")
# An empty line between first line and the result(more clear output)
return return

@ -145,7 +145,7 @@ def interpolate_string(object, username):
def CheckForParameter(username): def CheckForParameter(username):
'''checks if {?} exists in the username '''checks if {?} exists in the username
if exist it means that sherlock is looking for more multiple username''' if exist it means that sherlock is looking for more multiple username'''
return("{?}" in username) return ("{?}" in username)
checksymbols = [] checksymbols = []
@ -429,11 +429,11 @@ def sherlock(username, site_data, query_notify,
# Notify caller about results of query. # Notify caller about results of query.
result = QueryResult(username=username, result = QueryResult(username=username,
site_name=social_network, site_name=social_network,
site_url_user=url, site_url_user=url,
status=query_status, status=query_status,
query_time=response_time, query_time=response_time,
context=error_context) context=error_context)
query_notify.update(result) query_notify.update(result)
# Save status of request # Save status of request
@ -566,10 +566,10 @@ def main():
help="Include checking of NSFW sites from default list.") help="Include checking of NSFW sites from default list.")
args = parser.parse_args() args = parser.parse_args()
# If the user presses CTRL-C, exit gracefully without throwing errors # If the user presses CTRL-C, exit gracefully without throwing errors
signal.signal(signal.SIGINT, handler) signal.signal(signal.SIGINT, handler)
# Check for newer version of Sherlock. If it exists, let the user know about it # Check for newer version of Sherlock. If it exists, let the user know about it
try: try:
r = requests.get( r = requests.get(
@ -664,14 +664,14 @@ def main():
# Create notify object for query results. # Create notify object for query results.
query_notify = QueryNotifyPrint(result=None, query_notify = QueryNotifyPrint(result=None,
verbose=args.verbose, verbose=args.verbose,
print_all=args.print_all, print_all=args.print_all,
browse=args.browse) browse=args.browse)
# Run report on all specified users. # Run report on all specified users.
all_usernames = [] all_usernames = []
for username in args.username: for username in args.username:
if(CheckForParameter(username)): if (CheckForParameter(username)):
for name in MultipleUsernames(username): for name in MultipleUsernames(username):
all_usernames.append(name) all_usernames.append(name)
else: else:
@ -747,10 +747,7 @@ def main():
http_status = [] http_status = []
response_time_s = [] response_time_s = []
for site in results: for site in results:
if response_time_s is None: if response_time_s is None:
response_time_s.append("") response_time_s.append("")
else: else:
@ -761,11 +758,9 @@ def main():
url_user.append(results[site]["url_user"]) url_user.append(results[site]["url_user"])
exists.append(str(results[site]["status"].status)) exists.append(str(results[site]["status"].status))
http_status.append(results[site]["http_status"]) http_status.append(results[site]["http_status"])
DataFrame=pd.DataFrame({"username":usernames , "name":names , "url_main":url_main , "url_user":url_user , "exists" : exists , "http_status":http_status , "response_time_s":response_time_s})
DataFrame.to_excel(f'{username}.xlsx', sheet_name='sheet1', index=False)
DataFrame = pd.DataFrame({"username": usernames, "name": names, "url_main": url_main, "url_user": url_user, "exists": exists, "http_status": http_status, "response_time_s": response_time_s})
DataFrame.to_excel(f'{username}.xlsx', sheet_name='sheet1', index=False)
print() print()
query_notify.finish() query_notify.finish()

@ -3,9 +3,9 @@
This module contains various tests. This module contains various tests.
""" """
from tests.base import SherlockBaseTest from tests.base import SherlockBaseTest
import unittest
import secrets import secrets
class SherlockDetectTests(SherlockBaseTest): class SherlockDetectTests(SherlockBaseTest):
def test_detect_true_via_message(self): def test_detect_true_via_message(self):
"""Test Username Does Exist (Via Message). """Test Username Does Exist (Via Message).
@ -24,13 +24,13 @@ class SherlockDetectTests(SherlockBaseTest):
site = "AllMyLinks" site = "AllMyLinks"
site_data = self.site_data_all[site] site_data = self.site_data_all[site]
#Ensure that the site's detection method has not changed. # Ensure that the site's detection method has not changed.
self.assertEqual("message", site_data["errorType"]) self.assertEqual("message", site_data["errorType"])
self.username_check([site_data["username_claimed"]], self.username_check([site_data["username_claimed"]],
[site], [site],
exist_check=True exist_check=True
) )
return return
@ -51,13 +51,13 @@ class SherlockDetectTests(SherlockBaseTest):
site = "AllMyLinks" site = "AllMyLinks"
site_data = self.site_data_all[site] site_data = self.site_data_all[site]
#Ensure that the site's detection method has not changed. # Ensure that the site's detection method has not changed.
self.assertEqual("message", site_data["errorType"]) self.assertEqual("message", site_data["errorType"])
self.username_check([secrets.token_urlsafe(10)], self.username_check([secrets.token_urlsafe(10)],
[site], [site],
exist_check=False exist_check=False
) )
return return
@ -78,13 +78,13 @@ class SherlockDetectTests(SherlockBaseTest):
site = "9GAG" site = "9GAG"
site_data = self.site_data_all[site] site_data = self.site_data_all[site]
#Ensure that the site's detection method has not changed. # Ensure that the site's detection method has not changed.
self.assertEqual("status_code", site_data["errorType"]) self.assertEqual("status_code", site_data["errorType"])
self.username_check([site_data["username_claimed"]], self.username_check([site_data["username_claimed"]],
[site], [site],
exist_check=True exist_check=True
) )
return return
@ -105,18 +105,17 @@ class SherlockDetectTests(SherlockBaseTest):
site = "9GAG" site = "9GAG"
site_data = self.site_data_all[site] site_data = self.site_data_all[site]
#Ensure that the site's detection method has not changed. # Ensure that the site's detection method has not changed.
self.assertEqual("status_code", site_data["errorType"]) self.assertEqual("status_code", site_data["errorType"])
self.username_check([secrets.token_urlsafe(10)], self.username_check([secrets.token_urlsafe(10)],
[site], [site],
exist_check=False exist_check=False
) )
return return
class SherlockSiteCoverageTests(SherlockBaseTest): class SherlockSiteCoverageTests(SherlockBaseTest):
def test_coverage_false_via_response_url(self): def test_coverage_false_via_response_url(self):
"""Test Username Does Not Exist Site Coverage (Via Response URL). """Test Username Does Not Exist Site Coverage (Via Response URL).

Loading…
Cancel
Save