-
Notifications
You must be signed in to change notification settings - Fork 6
/
indexer.py
53 lines (38 loc) · 1.43 KB
/
indexer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
"""WARNING: Script is in beta and needs to be tested thoroughly.
The script generates a rudimentary appcache file based upon the content.opf file located in either:
an uncompressed epub directory or a compressed epub file and places it in the current directory
Usage: acm_gen.py --input='/path/to/content.opf' which links to the uncompressed epub directory that includes the content.opf
OR --input='/path/to/book.epub' which links to the compressed epub file
"""
__author__ = 'Futurepress'
__email__ = '[email protected]'
import os
import xml.etree.ElementTree as ET
import zipfile
import datetime
#import epub
from optparse import OptionParser
from epubsearch import EpubParser
from epubsearch import EpubIndexer
def get_parameters():
"""
Parse the user input
"""
parser = OptionParser()
parser.add_option('-i', '--input', dest='input')
(options, args) = parser.parse_args()
# code block to check for empty path, needed? path that includes proper filename, then valid file check
if not options.input:
options.input = "moby-dick"
else:
return {'input': options.input,'file': options.input[-3:].lower(), 'folder': options.input}
def main():
# get user defined parameters
userParams = get_parameters()
epub = EpubParser(userParams['folder'])
index = EpubIndexer('whoosh')
index.load(epub)
print 'Done!'
if __name__ == '__main__':
main()