Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 11-15-2011, 04:40 PM   #1
MikeBlyth
Junior Member
MikeBlyth began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Nov 2011
Location: Jos, Nigeria
Device: Kindle
Can't get print_version to do anything

I'm brand new to Calibre and haven't used Python for years. I am following the tutorial for custom news feeds. I notice that BBC printable pages are now of the form ...something?print=true, so I have added to the basic recipe

Code:
def print_version(self, url):
    return url.append(u'?print=true')
But nothing seems to happen. In fact, no matter what print_version returns, even garbage, the recipe still runs just the same. Using ebook-convert for debugging, the URLs fetched are unchanged. If I put a divide by zero line in there, still no error, so it seems the function is not even being called. I must be doing something fundamentally wrong!

Full recipe:
Code:
class AdvancedUserRecipe1321386207(BasicNewsRecipe):
    title          = u'BBC'
    oldest_article = 3
    max_articles_per_feed = 2
    auto_cleanup = True
    no_stylesheets = True
    feeds          = [(u'BBC Front Page', u'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml')]

def print_version(self, url):
    return url.append(u'?print=true')
MikeBlyth is offline   Reply With Quote
Old 11-15-2011, 09:04 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,331
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
When you call ebook-convert, call it with the full path to the edited recipe file.
kovidgoyal is offline   Reply With Quote
Advert
Old 11-16-2011, 02:41 AM   #3
MikeBlyth
Junior Member
MikeBlyth began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Nov 2011
Location: Jos, Nigeria
Device: Kindle
Yes, I'm using

ebook-convert c:\temp\test.recipe .epub --test -vv --debug-pipeline debug
MikeBlyth is offline   Reply With Quote
Old 11-16-2011, 04:03 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,331
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You need a indent before def it has to be in line with the rest of the contents of the class
kovidgoyal is offline   Reply With Quote
Old 11-16-2011, 07:36 AM   #5
MikeBlyth
Junior Member
MikeBlyth began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Nov 2011
Location: Jos, Nigeria
Device: Kindle
Aha, so that's what the tutorial meant about indentation ... I missed that--have been using Ruby too long. Thanks for the quick answer!
MikeBlyth is offline   Reply With Quote
Advert
Old 11-16-2011, 03:50 PM   #6
MikeBlyth
Junior Member
MikeBlyth began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Nov 2011
Location: Jos, Nigeria
Device: Kindle
Although the print_version method works fine now, the result is still not the print version of the BBC story. Perhaps it's something funny about BBC. Using the command line
wget http://www.bbc.co.uk/news/world-midd...260?print=true
gives the right page, printable form. However, if I modify print_version to
Code:
def print_version(self, url):
    return 'http://www.bbc.co.uk/news/world-middle-east-15762260?print=true'
the non-print, full version is used in the resulting epub (I'm just hard-coding the whole URL as a way to debug; in practice, the expression would be "return url + u'?print=true' "). I know it seems unbelievable and possibly I'm still doing something wrong, but I'm only having the problem with BBC.
MikeBlyth is offline   Reply With Quote
Old 11-17-2011, 11:12 AM   #7
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by MikeBlyth View Post
Although the print_version method works fine now, the result is still not the print version of the BBC story.
You probably should post your recipe, just in case there's something that someone can spot.
Starson17 is offline   Reply With Quote
Old 11-18-2011, 04:33 PM   #8
MikeBlyth
Junior Member
MikeBlyth began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Nov 2011
Location: Jos, Nigeria
Device: Kindle
Here is the recipe:
Code:
class AdvancedUserRecipe1321386207(BasicNewsRecipe):
    title          = u'BBC'
    oldest_article = 3
    max_articles_per_feed = 2
    auto_cleanup = True
    no_stylesheets = True
    feeds          = [(u'BBC Front Page', u'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml')]

    def print_version(self, url):
        return url + u'?print=true'
Maybe it will work for someone else?
MikeBlyth is offline   Reply With Quote
Old 11-18-2011, 08:47 PM   #9
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,331
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
The problem is probably that the RSS feed provides links to an intermediate page which is automatically redirected (this is done by websites for tracking purposes). So your print=true is being discarded during the redirect. To get around it you would need to implement the get_article_url method in your recipe to resolve the correct article url.
kovidgoyal is offline   Reply With Quote
Old 11-19-2011, 02:14 AM   #10
MikeBlyth
Junior Member
MikeBlyth began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Nov 2011
Location: Jos, Nigeria
Device: Kindle
Thanks.
MikeBlyth is offline   Reply With Quote
Old 11-19-2011, 04:33 PM   #11
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
your print=true is being discarded during the redirect. To get around it you would need to implement the get_article_url method in your recipe to resolve the correct article url.
To do this, add this to your recipe.
Code:
    def get_article_url(self, article):
        print article
        return None
The recipe won't produce anything, but you can check the printed results to see if the link you need is in there. You can check to see what link you need by checking where the print version link points to.
Starson17 is offline   Reply With Quote
Old 01-10-2012, 01:00 AM   #12
kiavash
Old Linux User
kiavash began at the beginning.
 
Posts: 36
Karma: 12
Join Date: Jan 2012
Device: NST
Did you find out why? I am having the same issue.

Edit:

Mine got solved this way:
PHP Code:
    def print_version(selfurl):
        print 
url
        
if url.find('/Journal/article.asp?HH_ID=') >= 0:
            return 
self.browser.open_novisit(url).geturl().replace('/Journal/article.asp?HH_ID=''/Journal/Print.asp?Id=')
        
elif  url.find('/News/article.asp?HH_ID=') >= 0:
            return 
self.browser.open_novisit(url).geturl().replace('/News/article.asp?HH_ID=''/Journal/Print.asp?Id=')
        
elif  url.find('/Resources/TechLib.asp?HH_ID=') >= 0:
            return 
self.browser.open_novisit(url).geturl().replace('/Resources/TechLib.asp?HH_ID=''/Resources/PrintRessource.asp?Id='

Last edited by kiavash; 01-10-2012 at 12:16 PM. Reason: Solved mine and posted the solution
kiavash is offline   Reply With Quote
Old 01-17-2012, 05:42 AM   #13
roedi06
Junior Member
roedi06 began at the beginning.
 
Posts: 9
Karma: 10
Join Date: Jan 2012
Device: SONY PRS-T1
I had the exact same problem the last days, the solution was very simple after all

I just entered the feed I provided to the script into the browser, in you case:
http://newsrss.bbc.co.uk/rss/newsonl...t_page/rss.xml

It will then redirect you to:
http://feeds.bbci.co.uk/news/rss.xml?edition=int

Put this link into you script instead of the first xml-link. Now use the
Code:
def print_version(self, url):
    return url + '?print=true')
to correct the link. This will probably fix your problem. Have a look into this link if you don't get it.

Last edited by roedi06; 01-17-2012 at 05:50 AM.
roedi06 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use print_version to get the print page of Starson17 Recipes 0 06-15-2011 12:05 PM
Using print_version for custom news source sexymax15 Recipes 0 06-15-2011 10:53 AM
SacBee print_version syntax thczv Recipes 6 04-12-2011 09:38 AM
Using PubDate in print_version of custom news source mobilereader72 Calibre 4 05-30-2009 05:52 PM


All times are GMT -4. The time now is 07:41 AM.


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