Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor spider_all function for improved efficiency and readability #3

Merged
merged 5 commits into from
Jul 21, 2024
Merged
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
29 changes: 17 additions & 12 deletions src/oculus/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,25 @@ def search_all(self, query:str, no_deduplicate:bool=False):
if not no_deduplicate:
self.collector.deduplicate()

def spider_all(self, query:str, depth:int=1, no_deduplicate:bool=False):
queries_made:List[str] = [f'{query}']
def spider_all(self, query: str, depth: int = 1, no_deduplicate: bool = False):
queries_made: set = {query}
self.search_all(query=query)
for iteration in range(depth):
new_queries:List[str] = []
new_queries.extend(self.collector.get_unique_usernames(spiderable_only=True))
new_queries.extend(self.collector.get_unique_emails(spiderable_only=True))
new_queries.extend(self.collector.get_unique_phones(spiderable_only=True))
new_queries.extend(self.collector.get_unique_fullnames(spiderable_only=True))
new_queries = list(set(new_queries)) # deduplication (for some reason set .update was problematic)

for i in range(depth):
new_queries: set = set()

new_queries.update(self.collector.get_unique_usernames(spiderable_only=True))
new_queries.update(self.collector.get_unique_emails(spiderable_only=True))
new_queries.update(self.collector.get_unique_phones(spiderable_only=True))
new_queries.update(self.collector.get_unique_fullnames(spiderable_only=True))

new_queries -= queries_made
ppfeister marked this conversation as resolved.
Show resolved Hide resolved
queries_made.update(new_queries)

for new_query in new_queries:
if new_query in queries_made:
continue
if loglevel >= LogLevel.SUCCESS_ONLY.value:
print(f'{Fore.BLUE}{Style.BRIGHT}[{Fore.RESET}Spider{Fore.BLUE}{Style.BRIGHT}]{Fore.RESET}{Style.RESET_ALL} {new_query}')
queries_made.append(new_query)
self.search_all(query=new_query)

if not no_deduplicate:
self.collector.deduplicate()
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@