Created
November 5, 2017 15:21
-
-
Save bholota/0494a616e6ce34db0aae2e425d46bc0a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
"""Script for converting PacktPub ebooks names in current directory. | |
Usage: | |
To execute just put script in ebook directory (subdirs will not work). | |
Todo: | |
- Detect unsupported or already converted file names. | |
""" | |
#!/usr/bin/python3 | |
#-*- encoding: utf-8 -*- | |
import re | |
import os | |
def fix_name(name): | |
"Return PacktPub pdf name without id with proper case" | |
name_id_matcher = re.search("^[0-9]{13}-", name) | |
name_id = name_id_matcher.group(0) | |
return name.replace(name_id, "").replace("_", " ").lower().capitalize() | |
def main(): | |
"Executes fix_name method for every file in current dir" | |
for filename in os.listdir("."): | |
os.rename(filename, fix_name(filename)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment