Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions sherlock_project/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
from colorama import Fore, Style
import webbrowser

# Global variable to count the number of results.
globvar = 0


class QueryNotify:
"""Query Notify Object.
Expand Down Expand Up @@ -132,6 +129,7 @@ def __init__(self, result=None, verbose=False, print_all=False, browse=False):
self.verbose = verbose
self.print_all = print_all
self.browse = browse
self._result_count = 0


def start(self, message):
Expand Down Expand Up @@ -169,9 +167,8 @@ def countResults(self):
Return Value:
The number of results by the time we call the function.
"""
global globvar
globvar += 1
return globvar
self._result_count += 1
return self._result_count

def update(self, result):
"""Notify Update.
Expand Down Expand Up @@ -258,7 +255,9 @@ def finish(self, message="The processing has been finished."):
Return Value:
Nothing.
"""
NumberOfResults = self.countResults() - 1
NumberOfResults = self._result_count
# The instance is shared across username scans, so reset the count for the next scan.
self._result_count = 0

print(Style.BRIGHT + Fore.GREEN + "[" +
Fore.YELLOW + "*" +
Expand Down
2 changes: 1 addition & 1 deletion sherlock_project/sherlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ def main():
DataFrame.to_excel(f"{username}.xlsx", sheet_name="sheet1", index=False)

print()
query_notify.finish()
query_notify.finish()


if __name__ == "__main__":
Expand Down
48 changes: 48 additions & 0 deletions tests/test_notify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import re
from sherlock_project.notify import QueryNotifyPrint
from sherlock_project.result import QueryResult, QueryStatus


def make_result(username, site):
return QueryResult(
username=username,
site_name=site,
site_url_user=f"https://example.com/{username}",
status=QueryStatus.CLAIMED,
query_time=None,
context=None,
)


def completed_count(out) -> str:
match = re.search(r"completed with\x1b\[37m (\d+)", out)
assert match is not None, f"no 'Search completed with N results' line in: {out!r}"
return match.group(1)


def test_count_is_per_instance(capsys):
qn_a = QueryNotifyPrint()
qn_b = QueryNotifyPrint()

qn_a.update(make_result("user1", "github"))
qn_a.update(make_result("user1", "twitter"))
qn_b.update(make_result("user2", "github"))

qn_a.finish()
assert completed_count(capsys.readouterr().out) == "2"

qn_b.finish()
assert completed_count(capsys.readouterr().out) == "1"


def test_count_resets_between_username_scans(capsys):
qn = QueryNotifyPrint()

qn.update(make_result("user1", "github"))
qn.update(make_result("user1", "twitter"))
qn.finish()
assert completed_count(capsys.readouterr().out) == "2"

qn.update(make_result("user2", "github"))
qn.finish()
assert completed_count(capsys.readouterr().out) == "1"