Guest User

Untitled

a guest
Apr 14th, 2020
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. from pathlib import Path
  2. import re
  3. import os
  4. import shutil
  5.  
  6. p = Path("")
  7.  
  8. books = list(p.glob('*.html'))
  9.  
  10. book_ids = {}
  11.  
  12. tot_books = 0
  13. tot_frontmatter = 0
  14. for book in books:
  15.     if "book-" in book.stem:
  16.         book_id = re.match(r'.*book-(.*)\)', book.stem).group(1)
  17.         book_ids[book_id] = book_ids.get(book_id, []) + [book.stem]
  18.  
  19.         if "frontmatter" in book.stem:
  20.             tot_frontmatter += 1
  21.  
  22.  
  23. for key in book_ids.keys():
  24.     os.mkdir(key)
  25.     for book in book_ids[key]:
  26.         shutil.move(book + ".html", key + "/" + book + ".html")
Advertisement
Add Comment
Please, Sign In to add comment