Created
July 31, 2014 23:37
-
-
Save quasiyoke/93b4f0931a7ab2c9992a to your computer and use it in GitHub Desktop.
FB2 library management helper
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
#!/usr/bin/env python | |
''' | |
Tool for renaming books. Unpacks zipped books and prompts to rename them. | |
''' | |
import os | |
import platform | |
import zipfile | |
IS_WINDOWS = 'Windows' == platform.system() | |
FILENAMES_ENCODING = IS_WINDOWS and 'cp1251' or 'utf8' | |
CONSOLE_ENCODING = IS_WINDOWS and 'cp866' or 'utf8' | |
files = os.listdir('.') | |
zips = [f for f in files if f.endswith('.zip')] | |
for f in zips: | |
z = zipfile.ZipFile(f) | |
z.extractall() | |
z.close() | |
os.remove(f) | |
files = os.listdir('.') | |
files = [unicode(f, FILENAMES_ENCODING) for f in files] | |
EXTENSION = '.fb2' | |
files = [f for f in files if f.endswith(EXTENSION)] | |
for f in sorted(files): | |
n = raw_input('\n\n' + f[:-len(EXTENSION)].encode(CONSOLE_ENCODING, 'ignore') + '\n') | |
if n: | |
n = unicode(n, CONSOLE_ENCODING) | |
os.rename(f, n + EXTENSION) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment