04-13-2020, 06:33 AM | #1 |
Groupie
Posts: 183
Karma: 266070
Join Date: Dec 2010
Device: Win7,Win10,Lubuntu,smartphone
|
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:
what I get in the plug-in window is (1): Spoiler:
but uncommenting either of the commented-out print() instructions, as: Spoiler:
gives instead (2): Spoiler:
- 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! |
04-13-2020, 09:29 AM | #2 |
Grand Sorcerer
Posts: 27,463
Karma: 192992430
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Pretty good discussion here on parsing/serializing the metadata fragment as pure xml with sigil_bs4.Beautiful soup.
And as mentioned in that discussion, /src/Resource_Files/python3lib/xmlprocessor.py in the Sigil source code (or Program Files\python3lib\xmlprocessor.py in a Windows Sigil installation) has examples on how to parse pure xml with bs4. |
Advert | |
|
04-13-2020, 09:51 AM | #3 |
Grand Sorcerer
Posts: 27,463
Karma: 192992430
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
As to why you're getting different output to the plugin runner window with what appears to be cosmetic-only changes: debug-printing to the plugin runner window is tricky at best. If your plugin is working as expected; trust that. Otherwise if you need to use extensive debug prints, it's almost always best to find a way to test your code outside of Sigil.
All output/results of a Sigil plugin are delivered back to Sigil's plugin window as an xml file. That xml file is then parsed and displayed via the plugin runner window. Depending on when, in the process, output with tags is printed, that output can actually get rendered by Qt instead displayed in its "raw" state. Last edited by DiapDealer; 04-13-2020 at 10:20 AM. |
04-13-2020, 12:31 PM | #4 | |
Groupie
Posts: 183
Karma: 266070
Join Date: Dec 2010
Device: Win7,Win10,Lubuntu,smartphone
|
Quote:
Spoiler:
my code prints normal. Looks like BeautifulSoup must dump back all the structure into place for thinks to behave as expected--one learns. BTW, can one define preferences as either Code:
prefs['mine'] = {source1:'value1',source2:'value2',...} prefs['mine'] = [('source1','value1'),('source2','value2'),...] |
|
04-13-2020, 12:51 PM | #5 |
Grand Sorcerer
Posts: 27,463
Karma: 192992430
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
You can use whatever you like for the preferences. Prefs are just a dictionary serialized to a json file. You can create your preferences as a dictionary of dictionaries, or as a dictionary of lists, or as a dictionary of lists of tuples if you like. It's just up to you to make sure the structure is properly populated before you save the preferences. Just like it's up to you parse the structure after retrieving the stored preferences.
I tend to use a dictionary of simple dictionaries, myself. Mostly for common grouping purposes. I've not really encountered a situation where complicating it much further than that would be an advantage. Your mileage may vary, though. |
Advert | |
|
04-13-2020, 12:58 PM | #6 |
Groupie
Posts: 183
Karma: 266070
Join Date: Dec 2010
Device: Win7,Win10,Lubuntu,smartphone
|
Thanks again!
|
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Stumped | dustyp | Library Management | 1 | 04-03-2020 06:14 PM |
BeautifulSoup on calibre | thiago.eec | Development | 5 | 01-15-2019 08:24 AM |
Private recipe repeatedly fails with BeautifulSoup find (calibre 3.6) | hiperlink | Recipes | 6 | 08-06-2017 07:56 AM |
I'm Stumped.... | 93terp | Amazon Kindle | 19 | 08-04-2016 04:27 PM |
Stumped | Grauheim | ePub | 5 | 10-21-2009 12:32 PM |