Creating a dict

pull/1955/head
Paulo Ricardo Mesquita 6 months ago
parent 638624daee
commit 3a36192205

@ -19,4 +19,6 @@ if __name__ == "__main__":
sys.exit(1)
import sherlock
sherlock.main()
response = sherlock.run()

@ -106,14 +106,9 @@ class QueryNotify:
Nicely formatted string to get information about this object.
"""
return str(self.result)
class QueryNotifyPrint(QueryNotify):
"""Query Notify Print Object.
Query notify class that prints results.
"""
class QueryNotifyDict(QueryNotify):
def __init__(self, result=None, verbose=False, print_all=False, browse=False):
"""Create Query Notify Print Object.
@ -136,34 +131,14 @@ class QueryNotifyPrint(QueryNotify):
self.verbose = verbose
self.print_all = print_all
self.browse = browse
self.data = dict()
return
def start(self, message):
"""Notify Start.
Will print the title to the standard output.
Keyword Arguments:
self -- This object.
message -- String containing username that the series
of queries are about.
Return Value:
Nothing.
"""
title = "Checking username"
print(Style.BRIGHT + Fore.GREEN + "[" +
Fore.YELLOW + "*" +
Fore.GREEN + f"] {title}" +
Fore.WHITE + f" {message}" +
Fore.GREEN + " on:")
# An empty line between first line and the result(more clear output)
print('\r')
return
def start(self, message=None):
# Sobrescreva este método conforme necessário
pass
def countResults(self):
"""This function counts the number of results. Every time the function is called,
@ -180,98 +155,13 @@ class QueryNotifyPrint(QueryNotify):
return globvar
def update(self, result):
"""Notify Update.
Will print the query result to the standard output.
Keyword Arguments:
self -- This object.
result -- Object of type QueryResult() containing
results for this query.
Return Value:
Nothing.
"""
self.result = result
response_time_text = ""
if self.result.query_time is not None and self.verbose is True:
response_time_text = f" [{round(self.result.query_time * 1000)}ms]"
# Output to the terminal is desired.
# Sobrescreva este método para salvar os dados no dicionário
if result.status == QueryStatus.CLAIMED:
self.countResults()
print(Style.BRIGHT + Fore.WHITE + "[" +
Fore.GREEN + "+" +
Fore.WHITE + "]" +
response_time_text +
Fore.GREEN +
f" {self.result.site_name}: " +
Style.RESET_ALL +
f"{self.result.site_url_user}")
if self.browse:
webbrowser.open(self.result.site_url_user, 2)
elif result.status == QueryStatus.AVAILABLE:
if self.print_all:
print(Style.BRIGHT + Fore.WHITE + "[" +
Fore.RED + "-" +
Fore.WHITE + "]" +
response_time_text +
Fore.GREEN + f" {self.result.site_name}:" +
Fore.YELLOW + " Not Found!")
elif result.status == QueryStatus.UNKNOWN:
if self.print_all:
print(Style.BRIGHT + Fore.WHITE + "[" +
Fore.RED + "-" +
Fore.WHITE + "]" +
Fore.GREEN + f" {self.result.site_name}:" +
Fore.RED + f" {self.result.context}" +
Fore.YELLOW + " ")
elif result.status == QueryStatus.ILLEGAL:
if self.print_all:
msg = "Illegal Username Format For This Site!"
print(Style.BRIGHT + Fore.WHITE + "[" +
Fore.RED + "-" +
Fore.WHITE + "]" +
Fore.GREEN + f" {self.result.site_name}:" +
Fore.YELLOW + f" {msg}")
else:
# It should be impossible to ever get here...
raise ValueError(
f"Unknown Query Status '{result.status}' for site '{self.result.site_name}'"
)
self.data[self.result.site_name] = self.result.site_url_user
return
def finish(self):
return self.data
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 2 last phrases.
Return Value:
Nothing.
"""
NumberOfResults = self.countResults() - 1
print(Style.BRIGHT + Fore.GREEN + "[" +
Fore.YELLOW + "*" +
Fore.GREEN + "] Search completed with" +
Fore.WHITE + f" {NumberOfResults} " +
Fore.GREEN + "results" + Style.RESET_ALL
)
def __str__(self):
"""Convert Object To String.
Keyword Arguments:
self -- This object.
Return Value:
Nicely formatted string to get information about this object.
"""
return str(self.result)

@ -5,4 +5,5 @@ from .sherlock_interpolate_string import interpolate_string
from .sherlock_future_session import SherlockFuturesSession
from .sherlock_timeout_check import timeout_check
from .sherlock_handler import handler
from .sherlock import run

@ -21,7 +21,7 @@ import requests
from torrequest import TorRequest
from result import QueryStatus
from result import QueryResult
from notify import QueryNotifyPrint
from notify import QueryNotifyDict
from sites import SitesInformation
from colorama import init
@ -322,7 +322,7 @@ def sherlock(username, site_data, query_notify,
return results_total
def main():
def run():
version_string = f"%(prog)s {__version__}\n" + \
f"{requests.__description__}: {requests.__version__}\n" + \
f"Python: {platform.python_version()}"
@ -500,7 +500,7 @@ def main():
sys.exit(1)
# Create notify object for query results.
query_notify = QueryNotifyPrint(result=None,
query_notify = QueryNotifyDict(result=None,
verbose=args.verbose,
print_all=args.print_all,
browse=args.browse)

Loading…
Cancel
Save