Created
February 25, 2020 18:15
-
-
Save mrchristine/95f02f0b59c239597d8183ec101c5f22 to your computer and use it in GitHub Desktop.
Find cloned notebooks and find most cloned
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $ 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