mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
636496f1dd
commit
5168e3c18b
@ -484,30 +484,29 @@ class HashableElement():
|
|||||||
def __getattr__(self, tag):
|
def __getattr__(self, tag):
|
||||||
return getattr(self.node, tag)
|
return getattr(self.node, tag)
|
||||||
|
|
||||||
|
def option_parser():
|
||||||
|
from calibre.utils.config import OptionParser
|
||||||
|
parser = OptionParser(usage='%prog: [options] file')
|
||||||
|
parser.add_option('-v', '--verbose', default=False, action='store_true',
|
||||||
|
dest='verbose',
|
||||||
|
help=_('Show detailed output information. Useful for debugging'))
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
import logging
|
from calibre.utils.logging import default_log
|
||||||
from optparse import OptionParser
|
parser = option_parser()
|
||||||
parser = OptionParser(usage="%prog: [options] [file]")
|
options, args = parser.parse_args()
|
||||||
parser.add_option('-v', '--verbose', action='store_true')
|
|
||||||
parser.add_option('-u', '--url', help="use URL instead of a local file")
|
|
||||||
(options, args) = parser.parse_args()
|
|
||||||
|
|
||||||
if not (len(args) == 1 or options.url):
|
if len(args) != 1:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(1)
|
raise SystemExit(1)
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
|
with open(args[0], 'rb') as f:
|
||||||
|
raw = f.read()
|
||||||
|
|
||||||
file = None
|
|
||||||
if options.url:
|
|
||||||
import urllib
|
|
||||||
file = urllib.urlopen(options.url)
|
|
||||||
else:
|
|
||||||
file = open(args[0], 'rt')
|
|
||||||
enc = sys.__stdout__.encoding or 'utf-8'
|
enc = sys.__stdout__.encoding or 'utf-8'
|
||||||
try:
|
print Document(raw, default_log, debug=options.verbose).summary().encode(enc, 'replace')
|
||||||
print Document(file.read(), debug=options.verbose).summary().encode(enc, 'replace')
|
|
||||||
finally:
|
|
||||||
file.close()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user