From 7963e888a3fb7d26ca8b37cfec2ffa0b67a70326 Mon Sep 17 00:00:00 2001 From: Sukesh Kumar Date: Wed, 12 Aug 2026 13:34:32 +0530 Subject: [PATCH] notify: make result counter per-instance and reset between username scans --- sherlock_project/notify.py | 13 +++++----- sherlock_project/sherlock.py | 2 +- tests/test_notify.py | 48 ++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 tests/test_notify.py diff --git a/sherlock_project/notify.py b/sherlock_project/notify.py index ab6f5a3866..f95c12cf44 100644 --- a/sherlock_project/notify.py +++ b/sherlock_project/notify.py @@ -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. @@ -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): @@ -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. @@ -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 + "*" + diff --git a/sherlock_project/sherlock.py b/sherlock_project/sherlock.py index e037d39458..ea59d1a206 100644 --- a/sherlock_project/sherlock.py +++ b/sherlock_project/sherlock.py @@ -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__": diff --git a/tests/test_notify.py b/tests/test_notify.py new file mode 100644 index 0000000000..60cae0650c --- /dev/null +++ b/tests/test_notify.py @@ -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" \ No newline at end of file