View Single Post
Old 04-13-2020, 06:33 AM   #1
carmenchu
Groupie
carmenchu ought to be getting tired of karma fortunes by now.carmenchu ought to be getting tired of karma fortunes by now.carmenchu ought to be getting tired of karma fortunes by now.carmenchu ought to be getting tired of karma fortunes by now.carmenchu ought to be getting tired of karma fortunes by now.carmenchu ought to be getting tired of karma fortunes by now.carmenchu ought to be getting tired of karma fortunes by now.carmenchu ought to be getting tired of karma fortunes by now.carmenchu ought to be getting tired of karma fortunes by now.carmenchu ought to be getting tired of karma fortunes by now.carmenchu ought to be getting tired of karma fortunes by now.
 
Posts: 193
Karma: 266070
Join Date: Dec 2010
Location: Spain
Device: Win10,Win11,Ubuntu,PockbookLux44
Stumped, help!: bk.getmetadataxml() + BeautifulSoup

I am working on the attached plug-in (works, but only reports: under construction), to customize the metadata in the opf file.
Trouble is, when pass it to soup, as
Spoiler:
Code:
from sigil_bs4 import BeautifulSoup
from sigil_bs4.builder._lxml import LXMLTreeBuilderForXML # From xmlsouptest
.........
metadata = bk.getmetadataxml()
    ##### Uncomment either for the metada_soup to work
    # print(bk.getmetadataxml()) 
    # print(metadata)
    ############
    metadata_soup = BeautifulSoup(bk.getmetadataxml(), 'lxml') # 'lxml', 'xml'
    print('soup= ',metadata_soup, '\n')

what I get in the plug-in window is (1):
Spoiler:
Code:
Status: success
soup= 
fiction science fiction 52c38ef6-669b-488c-8307-71d9cc6d3ff5 1950-04-15T05:00:00+00:00 Stilson, Charles Billings en Polaris and the Goddess Glorian Distributed Proofreaders Canada 2020-04-06 Stilson, Charles Billings should be list Stilson, Charles Billings should be whole tag old author: dc:creator ['Stilson', ' Charles Billings'] authorSort Charles Billings Stilson authorName [( Charles Billings Stilson, ' Charles Billings Stilson'), ( Charles Billings Stilson, 'file:asStilson, Charles Billings')] Done

but uncommenting either of the commented-out print() instructions, as:
Spoiler:
Code:
metadata = bk.getmetadataxml()
    ##### Uncomment either for the metada_soup to work
    # print(bk.getmetadataxml()) 
    print(metadata)
    ############
    metadata_soup = BeautifulSoup(bk.getmetadataxml(), 'lxml') # 'lxml', 'xml'
    print('soup= ',metadata_soup, '\n')

gives instead (2):
Spoiler:
Code:
Status: success

<metadata xmlns:calibre="http://calibre.kovidgoyal.net/2009/metadata" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<dc:subject>fiction</dc:subject>
<dc:subject>science fiction</dc:subject>
<dc:identifier id="uuid_id" opf:scheme="uuid">52c38ef6-669b-488c-8307-71d9cc6d3ff5</dc:identifier>
<dc:date>1950-04-15T05:00:00+00:00</dc:date>
<dc:creator opf:file-as="Unknown" opf:role="aut">Stilson, Charles Billings</dc:creator>
<dc:language>en</dc:language>
<meta name="cover" content="cover"/>
<meta name="calibre:timestamp" content="2019-04-03T00:35:53.586000+00:00"/>
<dc:title>Polaris and the Goddess Glorian</dc:title>
<dc:publisher>Distributed Proofreaders Canada</dc:publisher>
<meta name="Sigil version" content="1.2.0"/>
<dc:date xmlns:opf="http://www.idpf.org/2007/opf" opf:event="modification">2020-04-06</dc:date>
</metadata>

soup=  <html><body><metadata xmlns:calibre="http://calibre.kovidgoyal.net/2009/metadata" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<dc:subject>fiction</dc:subject>
<dc:subject>science fiction</dc:subject>
<dc:identifier id="uuid_id" opf:scheme="uuid">52c38ef6-669b-488c-8307-71d9cc6d3ff5</dc:identifier>
<dc:date>1950-04-15T05:00:00+00:00</dc:date>
<dc:creator opf:file-as="Unknown" opf:role="aut">Stilson, Charles Billings</dc:creator>
<dc:language>en</dc:language>
<meta content="cover" name="cover"/>
<meta content="2019-04-03T00:35:53.586000+00:00" name="calibre:timestamp"/>
<dc:title>Polaris and the Goddess Glorian</dc:title>
<dc:publisher>Distributed Proofreaders Canada</dc:publisher>
<meta content="1.2.0" name="Sigil version"/>
<dc:date opf:event="modification" xmlns:opf="http://www.idpf.org/2007/opf">2020-04-06</dc:date>
</metadata>
</body></html> 

<dc:creator opf:file-as="Unknown" opf:role="aut">Stilson, Charles Billings</dc:creator> should be list

<dc:creator opf:file-as="Unknown" opf:role="aut">Stilson, Charles Billings</dc:creator> should be whole tag

old author:  dc:creator 

['Stilson', ' Charles Billings']  authorSort
 Charles Billings Stilson  authorName
[(<dc:creator opf:file-as="Stilson, Charles Billings" opf:role="aut"> Charles Billings Stilson</dc:creator>, ' Charles Billings Stilson'), (<dc:creator opf:file-as="Stilson, Charles Billings" opf:role="aut"> Charles Billings Stilson</dc:creator>, 'file:asStilson, Charles Billings')]

Done

- It drove me batty, to spot *when* the 'type (2)' report, with tags, would become 'type (1)'--not a single tag in sight--while I hadn't done anything that looked significant (comment/uncomment a print() instruction shouldn't be only cosmetic?)
- Please, am I missing something? Some format instruction to be added in situation (1)?
The internal works (navigation & assignments) seem right, but the soup doesn't look adequate for dropping back into the opf file...

Greatly appreciate any help: (stumped)**3!
Attached Files
File Type: zip CustomizeOPF_V0_0.zip (3.8 KB, 301 views)
carmenchu is offline   Reply With Quote