<commit_before>import os
from xml.dom import minidom
import shutil

ebooks_directory = "/home/mendhak/Desktop/EBooks"


def getCalibreId(opfPath):
    xmldoc = minidom.parse(opfPath)
    itemlist = xmldoc.getElementsByTagName('dc:identifier')
    for identifier in itemlist:
        if 'id' in identifier.attributes.keys() and identifier.attributes['id'].value == 'calibre_id':
            return identifier.childNodes[0].data

for root, dirs, files in os.walk(ebooks_directory):
    for file in files:
        if file.endswith('metadata.opf'):
            calibre_id = getCalibreId(os.path.join(root, file))
            calibre_fragment = " (" + calibre_id + ")"
            if calibre_fragment not in root:
                print "Moving files to " + os.path.join(root + calibre_fragment)
                shutil.rmtree(os.path.join(root+calibre_fragment), ignore_errors=True)
                shutil.move(os.path.join(root), os.path.join(root+calibre_fragment))



<commit_msg>Prompt user for path to directory<commit_after>import os
import sys
from xml.dom import minidom
import shutil

#ebooks_directory = "/home/mendhak/Desktop/EBooks"
ebooks_directory = raw_input("Enter path to your ebooks directory: ")

print ebooks_directory
if ebooks_directory is None or len(ebooks_directory) < 3:
    print "Please enter a proper directory path"
    exit(1)



def getCalibreId(opfPath):
    xmldoc = minidom.parse(opfPath)
    itemlist = xmldoc.getElementsByTagName('dc:identifier')
    for identifier in itemlist:
        if 'id' in identifier.attributes.keys() and identifier.attributes['id'].value == 'calibre_id':
            return identifier.childNodes[0].data

for root, dirs, files in os.walk(ebooks_directory):
    for file in files:
        if file.endswith('metadata.opf'):
            calibre_id = getCalibreId(os.path.join(root, file))
            calibre_fragment = " (" + calibre_id + ")"
            if calibre_fragment not in root:
                print "Moving files to " + os.path.join(root + calibre_fragment)
                shutil.rmtree(os.path.join(root+calibre_fragment), ignore_errors=True)
                shutil.move(os.path.join(root), os.path.join(root+calibre_fragment))




{'fraction_non_alphanumeric': 0.10681818181818181, 'fraction_numerical': 0.0018181818181818182, 'mean_word_length': 3.224568138195777, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1487990', 'n_tokens_mistral': 723, 'n_tokens_neox': 699, 'n_words': 153}