forked from rschroll/prsannots
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetannotations
More file actions
executable file
·65 lines (56 loc) · 2.13 KB
/
Copy pathgetannotations
File metadata and controls
executable file
·65 lines (56 loc) · 2.13 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
"""
%s mount-point
Find all annotated PDFs on the Sony PRS-T1 mounted at the specified
mount point, and present a menu to let the user chose to export one
of them with annotations. Currently, the freehand annotations,
highlights, and highlights with text notes are supported.
"""
# Copyright 2012-2013 Robert Schroll
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
import os
import sys
import pyPdf
from prsannots.prst1 import Reader
from prsannots.misc import u_raw_input, u_print, u_argv
def select_book(books):
u_print("Please select which book to get:")
for i, book in enumerate(books):
title = book.title or book.file.split('/')[-1]
u_print(" %i. %s" % (i+1, title))
which = u_raw_input("> ")
try:
return books[int(which) - 1]
except (ValueError, IndexError):
u_print("Could not understand your response. Aborting.")
sys.exit(1)
def main(path):
reader = Reader(path)
book = select_book(reader.books)
outfn = os.path.splitext(os.path.basename(book.file))[0] + '.annot.pdf'
userfn = u_raw_input("Enter output file name [%s]: " % outfn)
if userfn:
outfn = userfn
book.write_annotated_pdf(open(outfn, 'wb'))
if __name__ == '__main__':
if len(u_argv) != 2:
u_print(__doc__ % sys.argv[0])
sys.exit(0)
if not os.path.ismount(u_argv[1]):
u_print("First argument must be mount point of Sony Reader.")
u_print("(%s does not appear to be a mount point.)" % sys.argv[1])
sys.exit(1)
main(sys.argv[1])