Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 01-26-2014, 03:59 PM   #1
geekraver
Addict
geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.
 
Posts: 364
Karma: 1035291
Join Date: Jul 2006
Location: Redmond, WA
Device: iPad Mini,Kindle Paperwhite
Using Beautiful Soup from a plugin

Hi devs

I am working on a plugin for which I want to use Beautiful Soup. However, my plugin fails on the import:

from bs4 import BeautifulSoup

with:

File "calibre_plugins.magazines.bs4.__init__", line 30, in <module>
File "site-packages/calibre/customize/zipplugin.py", line 179, in load_module
File "calibre_plugins.magazines.bs4.builder.__init_ _", line 4, in <module>
ImportError: No module named bs4.element

This is if I bundle bs4 with the plugin. If I don't, and try to rely on the fact that it is installed in my Python distribution, then I get:

File "calibre_plugins.magazines.worker", line 15, in <module>
ImportError: No module named bs4

Has anyone used bs4 in a plugin and have any tips?

Thanks!
geekraver is offline   Reply With Quote
Old 01-26-2014, 04:28 PM   #2
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,552
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
1) calibre's python environment already comes with BeautifulSoup, so unless there's an issue with needing a specific version, I'd just import that.

2) Modules included within a plugin's package are only available for import during the "run" method of the plugin (at least that always used to be the case).

2) Import modules using the name of the text-file included in your plugin.

ex: if the filename is "plugin-import-name-my_shiny_plugin.txt" you would use:
Code:
from calibre_plugins.my_shiny_plugin import my_shiny_module
3) You can't rely on modules installed in your machine's Python installation, because calibre doesn't use your Python installation.

Last edited by DiapDealer; 01-26-2014 at 04:44 PM.
DiapDealer is offline   Reply With Quote
Advert
Old 01-26-2014, 04:34 PM   #3
geekraver
Addict
geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.
 
Posts: 364
Karma: 1035291
Join Date: Jul 2006
Location: Redmond, WA
Device: iPad Mini,Kindle Paperwhite
Great, thanks! Have it working now.
geekraver is offline   Reply With Quote
Old 01-26-2014, 05:29 PM   #4
geekraver
Addict
geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.geekraver ought to be getting tired of karma fortunes by now.
 
Posts: 364
Karma: 1035291
Join Date: Jul 2006
Location: Redmond, WA
Device: iPad Mini,Kindle Paperwhite
Are there any known issues with the Beautiful Soup that is bundled with Calibre? I'm finding that from within my plugin, a soup.find(class_="foo") is returning None, while in my test script hitting the same URL it works and finds the div I want. I logged the page contents and they look fine so everything seems to be working up to the point I call find (I can copy the metadata log to the clipboard and paste it in an editor and see the element that the find failed to locate).

EDIT: I notice that doing finds by id seems to work, but not finds by class.

EDIT: the above was the key. The soup distributed with Calibre is an older version that doesn't support the class_ parameter. Instead you must use:

find(attrs={'class':'foo'})

Last edited by geekraver; 01-26-2014 at 06:39 PM.
geekraver is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unutterably Silly Is chicken soup an abomination? AprilHare Lounge 599 12-09-2015 03:15 AM
Parsing Chron.com with Beautiful Soup dkfurrow Recipes 12 11-02-2013 09:10 AM
Beautiful soup findAll doesn't seem to work Steven630 Recipes 13 08-19-2012 02:44 AM
Word Soup kranu Amazon Kindle 8 03-11-2011 04:25 PM
Supernatural soup bmwvan Reading Recommendations 30 08-01-2008 11:25 PM


All times are GMT -4. The time now is 04:52 AM.


MobileRead.com is a privately owned, operated and funded community.