Skip to content

Instantly share code, notes, and snippets.

@mrchristine
Created February 25, 2020 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrchristine/95f02f0b59c239597d8183ec101c5f22 to your computer and use it in GitHub Desktop.
Save mrchristine/95f02f0b59c239597d8183ec101c5f22 to your computer and use it in GitHub Desktop.
Find cloned notebooks and find most cloned
# $ cat nb_names.log | sort | uniq -c | sort -nrk1 | head
import os, re
# find cloned notebooks with parens
pattern = re.compile(r"\((\d+)\)")
with open('user_workspace.log', 'r') as fp, open('nb_names.log', 'w') as fp_w:
for x in fp:
nb_name = os.path.basename(x.rstrip())
m = pattern.findall(nb_name)
if m:
clone_num = '({0})'.format(m[0])
clone_indx = nb_name.find(clone_num)
clean_nb_name = nb_name[:clone_indx].rstrip()
fp_w.write(clean_nb_name + '\n')
else:
fp_w.write(nb_name + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment