View Single Post
Old 08-09-2019, 05:16 AM   #19
Vroni
Banned
Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'Vroni knows the difference between 'who' and 'whom'
 
Posts: 168
Karma: 10010
Join Date: Oct 2018
Device: Tolino/PRS 650/Tablet
Quote:
Originally Posted by DiapDealer View Post
This plugin prints the xml snippet that bk.getmetadata() returns, prints the soup made from that snippet, adds the dc:language entry if not present, serializes the soup and prints the results, then ultimately writes the xml snippet back with bk.setmetadata().
Thats the expected result, but it adds a second (third foruth and so on) dc_language element all the time From the documentation find() returns None if it finds nothing and in that case if adds it and sets the language ex_us.

So whats wrong with if not dc_language: ? If should not insert something, just changing.

Before:

Code:
  <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
    <dc:identifier id="BookId" opf:scheme="UUID">urn:uuid:7967fadc-d511-42ee-aad1-a472e662546a</dc:identifier>
    <dc:language>de</dc:language>
    <dc:title>[Title here]</dc:title>
  </metadata>
After

Code:
<?xml version="1.0" encoding="utf-8" ?>
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
  <dc:identifier id="BookId" opf:scheme="UUID">urn:uuid:7967fadc-d511-42ee-aad1-a472e662546a</dc:identifier>
  <dc:language>de</dc:language>
  <dc:title>[Title here]</dc:title>
  <dc:language>en-US</dc:language>
</metadata>
By the way, the parser adds the xml starting declaration. At least, that doesnt mess up the content.opf file.



What my Python abilities now exceed is that if not dc_language statement does work. Debugging the code with print(): the content of the Variable is None

Vroni
Vroni is offline   Reply With Quote