Skip to content

Instantly share code, notes, and snippets.

@JupyterJones
Created February 15, 2023 03:41
Show Gist options
  • Save JupyterJones/1305dd124d15745c2747c230c731a9d0 to your computer and use it in GitHub Desktop.
Save JupyterJones/1305dd124d15745c2747c230c731a9d0 to your computer and use it in GitHub Desktop.
search jupyter notebooks in a directory for passwords
import os
search_dir = '/home/jack/Desktop/HDD500/notebooks' # Replace this with the directory where you want to search for Jupyter notebooks
search_string = 'passwords' # Replace this with the string you want to search for
output_file = 'contains_passwords.txt' # Replace this with the output file name
with open(output_file, 'w') as f:
for file in os.listdir(search_dir):
if file.endswith('.ipynb'):
with open(os.path.join(search_dir, file), 'r', encoding='utf-8') as nb_file:
nb_content = nb_file.read()
if search_string in nb_content:
f.write(file + '\n')
print(f"Done searching for '{search_string}'. Results saved to '{output_file}'.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment