Ejemplo n.º 1
0
 def get_topaz_highlight(displayed_location):
     # Parse My Clippings.txt for a matching highlight
     # Search looks for book title match, highlight match, and location match
     # Author is not matched
     # This will find the first instance of a clipping only
     book_fs = self.path.replace('.%s' % self.bookmark_extension,'.%s' % self.book_format)
     with lopen(book_fs,'rb') as f2:
         stream = StringIO(f2.read())
         mi = get_topaz_metadata(stream)
     my_clippings = self.path
     split = my_clippings.find('documents') + len('documents/')
     my_clippings = my_clippings[:split] + "My Clippings.txt"
     try:
         with lopen(my_clippings, 'r') as f2:
             marker_found = 0
             text = ''
             search_str1 = '%s' % (mi.title)
             search_str2 = '- Highlight Loc. %d' % (displayed_location)
             for line in f2:
                 if marker_found == 0:
                     if line.startswith(search_str1):
                         marker_found = 1
                 elif marker_found == 1:
                     if line.startswith(search_str2):
                         marker_found = 2
                 elif marker_found == 2:
                     if line.startswith('=========='):
                         break
                     text += line.strip()
             else:
                 raise Exception('error')
     except:
         text = '(Unable to extract highlight text from My Clippings.txt)'
     return text
Ejemplo n.º 2
0
 def get_topaz_highlight(displayed_location):
     # Parse My Clippings.txt for a matching highlight
     # Search looks for book title match, highlight match, and location match
     # Author is not matched
     # This will find the first instance of a clipping only
     book_fs = self.path.replace('.%s' % self.bookmark_extension,'.%s' % self.book_format)
     with lopen(book_fs,'rb') as f2:
         stream = io.BytesIO(f2.read())
         mi = get_topaz_metadata(stream)
     my_clippings = self.path
     split = my_clippings.find('documents') + len('documents/')
     my_clippings = my_clippings[:split] + "My Clippings.txt"
     try:
         with open(my_clippings, encoding='utf-8', errors='replace') as f2:
             marker_found = 0
             text = ''
             search_str1 = '%s' % (mi.title)
             search_str2 = '- Highlight Loc. %d' % (displayed_location)
             for line in f2:
                 if marker_found == 0:
                     if line.startswith(search_str1):
                         marker_found = 1
                 elif marker_found == 1:
                     if line.startswith(search_str2):
                         marker_found = 2
                 elif marker_found == 2:
                     if line.startswith('=========='):
                         break
                     text += line.strip()
             else:
                 raise Exception('error')
     except:
         text = '(Unable to extract highlight text from My Clippings.txt)'
     return text