URI: 
       Add formatting for GPH, publish to files - bookdarts - Extract KOReader generated highlights and publish them in a variety of formats↵
   DIR Log
   DIR Files
   DIR Refs
       ---
   DIR commit bf2ac9859ab8bb75fa728c89a9d6682f98931d4d
   DIR parent a2eec07ead104ba756d1abb0b6f727cd4e369632
  HTML Author: Scarlett McAllister <no+reply@roygbyte.com>
       Date:   Thu, 28 Sep 2023 20:53:43 -0300
       
       Add formatting for GPH, publish to files
       
       Diffstat:
         M bookdarts.py                        |      52 +++++++++++++++++++++++--------
       
       1 file changed, 39 insertions(+), 13 deletions(-)
       ---
   DIR diff --git a/bookdarts.py b/bookdarts.py
       @@ -50,16 +50,38 @@ def format_document(document):
                document['filename'] = completed_proc.stdout\
                                  .decode('UTF-8')\
                                  .lower()\
       -                          .replace(' ', '_')
       +                          .replace(' ', '_')\
       +                          + ".txt"
       +        # Trim link label to doc width.
       +        # document['link_label'] = document['title']
       +        document['link_label'] = (document['title'] \
       +                                  if (len(document['title']) <= EXPORT['DOC_WIDTH']) \
       +                                  else document['title'][:(EXPORT['DOC_WIDTH'] - 4)] + " ...")
       +        document['entries'] = map(format_entry,
       +                                  list(document['entries']))
       +        return document
            except CalledProcessError as e:
                print("Exception:", e)
       -        
       -    document['link_label'] = document['title']
       -    document['entries'] = map(format_entry,
       -                              list(document['entries']))
       -    # Trim link label to doc size
       -    # document['link_label'] = document['title'][:EXPORT['DOC_WIDTH']] + "..."
       -    return document
       +        exit
       +
       +def format_document_gph_link(document):
       +    return "[%s|%s|%s|%s|%s]" %\
       +        (1, # Type
       +         document['link_label'], # Selector
       +         document['filename'], # Path to file
       +         "", # Host
       +         70)
       +
       +def publish_index(documents):
       +    with open("publish/index.gph", "w", encoding="UTF-8") as file:        
       +        for document in documents:
       +            file.write(format_document_gph_link(document) + "\n")
       +
       +def publish_entries(entries, document):
       +    "Need the entries for the document and the given document."
       +    with open (f"publish/documents/{document['filename']}",
       +               "w", encoding="UTF-8") as file:
       +        file.write("\n\n".join(entries))
        
        #############################################
        # Main control flow
       @@ -70,14 +92,18 @@ strin = ""
        documents = []
        for line in fileinput.input(encoding="utf-8"):
            strin += line
       -
        try:
            documents = json.loads(strin)['documents']
        except JSONDecodeError as e:
            print("Error decoding JSON. Exiting.",
                  f'{e.msg=} {e.pos=} {e.lineno=}')
            exit
       -
       -for document in list(map(format_document, documents)):
       -    print("\n#",document['title'])
       -    print("\n\n".join(document['entries']))
       +formatted_documents = list(map(format_document, documents))
       +publish_index(formatted_documents)
       +for document in formatted_documents:
       +    publish_entries(document['entries'], document)
       +    # Port
       +# Format the documents and then print them
       +# for document in list(map(format_document, documents)):
       +    # print("\n#",document['title'])
       +    # print("\n\n".join(document['entries']))