mirror of
https://github.com/sherlock-project/sherlock
synced 2024-12-03 17:09:16 +00:00
Move all writing of output files to occur after query takes place. Use with statement for results file, as that is more graceful on errors. Use try block for result directory creation: this has a smaller window for a race condition.
This commit is contained in:
parent
123e4d47e0
commit
2e195d4439
1 changed files with 22 additions and 19 deletions
|
@ -599,17 +599,6 @@ def main():
|
|||
for username in args.username:
|
||||
print()
|
||||
|
||||
if args.output:
|
||||
file = open(args.output, "w", encoding="utf-8")
|
||||
elif args.folderoutput: # In case we handle multiple usernames at a targetted folder.
|
||||
# If the folder doesnt exist, create it first
|
||||
if not os.path.isdir(args.folderoutput):
|
||||
os.mkdir(args.folderoutput)
|
||||
file = open(os.path.join(args.folderoutput,
|
||||
username + ".txt"), "w", encoding="utf-8")
|
||||
else:
|
||||
file = open(username + ".txt", "w", encoding="utf-8")
|
||||
|
||||
results = sherlock(username,
|
||||
site_data,
|
||||
verbose=args.verbose,
|
||||
|
@ -620,14 +609,28 @@ def main():
|
|||
timeout=args.timeout,
|
||||
color=not args.no_color)
|
||||
|
||||
exists_counter = 0
|
||||
for website_name in results:
|
||||
dictionary = results[website_name]
|
||||
if dictionary.get("status").status == QueryStatus.CLAIMED:
|
||||
exists_counter += 1
|
||||
file.write(dictionary["url_user"] + "\n")
|
||||
file.write(f"Total Websites Username Detected On : {exists_counter}")
|
||||
file.close()
|
||||
if args.output:
|
||||
result_file = args.output
|
||||
elif args.folderoutput:
|
||||
# The usernames results should be stored in a targeted folder.
|
||||
# If the folder doesnt exist, create it first
|
||||
try:
|
||||
os.mkdir(args.folderoutput)
|
||||
except FileExistsError:
|
||||
#directory already exists
|
||||
pass
|
||||
result_file = os.path.join(args.folderoutput, f"{username}.txt")
|
||||
else:
|
||||
result_file = f"{username}.txt"
|
||||
|
||||
with open(result_file, "w", encoding="utf-8") as file:
|
||||
exists_counter = 0
|
||||
for website_name in results:
|
||||
dictionary = results[website_name]
|
||||
if dictionary.get("status").status == QueryStatus.CLAIMED:
|
||||
exists_counter += 1
|
||||
file.write(dictionary["url_user"] + "\n")
|
||||
file.write(f"Total Websites Username Detected On : {exists_counter}")
|
||||
|
||||
if args.csv == True:
|
||||
with open(username + ".csv", "w", newline='', encoding="utf-8") as csv_report:
|
||||
|
|
Loading…
Reference in a new issue