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 01-03-2011, 08:03 PM   #1
Tegan
Connoisseur
Tegan began at the beginning.
 
Posts: 59
Karma: 10
Join Date: Jan 2011
Device: Kindle 1st Gen, Kindle 3 SO
Request for Recipes: Yakima Valley Newspapers

Tri-City Herald Mid-Columbia - http://www.tri-cityherald.com/901/index.rss
Yakima Herald Online - http://feeds.feedburner.com/yhronlinenews


I'd also like to see a recipe for the Seattle PI, which is online only now:
Local News - http://www.seattlepi.com/rss/local_2.rss
Opinion - http://www.seattlepi.com/rss/opinion_2.rss

Other Seattle PI feeds are listed at:
http://www.seattlepi.com/rss/


Also, is there a way to rotate the images in the gocomics or comics feeds to make 'em display larger (and therefore better) in my Kindle? Ideally, I would love a way to have the images in a comics recipe display the shortest side as the width and the longest side as the height, rotating them only if it makes sense. I'm guessing that would be a really hard fix requiring coding change, though, so I thought I'd just ask if it already exists or is likely to ever exist.
Tegan is offline   Reply With Quote
Old 01-13-2011, 03:34 PM   #2
Tegan
Connoisseur
Tegan began at the beginning.
 
Posts: 59
Karma: 10
Join Date: Jan 2011
Device: Kindle 1st Gen, Kindle 3 SO
Ok, I've done my own recipe for the first two links. I put them together, because they are both of interest to me here. My solutions weren't particularly elegant, I just kept trying to figure out how to snip away the stuff that wasn't of interest. In the Tri-City Herald I lost all the images because I couldn't figure out how to display them without a whole bunch of extra text.

I think I'll take a crack at the Seattle PI feeds now, but there are a few other sites I want to try now that I have a slight notion of what I can do.
Tegan is offline   Reply With Quote
Advert
Old 01-13-2011, 04:51 PM   #3
Tegan
Connoisseur
Tegan began at the beginning.
 
Posts: 59
Karma: 10
Join Date: Jan 2011
Device: Kindle 1st Gen, Kindle 3 SO
Ok, I've got an odd one... I redid the Tri-City Herald Mid-Columbia recipe to try to recover those images. And it worked, I got 'em. But they show up at the bottom of the article instead of under the headline with the caption. Is there a way to move the items within an article around, so I could either move the image up or put the caption down where it belongs?

Code:
class AdvancedUserRecipe1294886492(BasicNewsRecipe):
    title          = u'Tri-City Herald'
    description    = 'The Tri-City Herald Mid-Columbia.'
    __author__     = 'Laura Gjovaag'
    oldest_article        = 1.5
    max_articles_per_feed = 100
    no_stylesheets        = True
    remove_javascript     = True
    keep_only_tags = [
                      dict(name='div', attrs={'id':['story_header', 'cycleImageCaption', 'story_body']})
                      dict(name='img', attrs={'class':'imageCycle'}),
                      ]
    remove_tags    = [
                      dict(name='div', attrs={'id':'story_mlt'}),
                      dict(name='a', attrs={'id':'commentCount'}),
                      dict(name=['script', 'noscript', 'style'])]
    extra_css      = 'h1{font: bold 140%;} #cycleImageCaption{font: monospace 60%}'

    feeds          = [
                      (u'Tri-City Herald Mid-Columbia', u'http://www.tri-cityherald.com/901/index.rss')
                     ]
Tegan is offline   Reply With Quote
Old 01-13-2011, 05:18 PM   #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: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
The postprocess_html method is what you're looking for.
kovidgoyal is offline   Reply With Quote
Old 01-13-2011, 05:18 PM   #5
Tegan
Connoisseur
Tegan began at the beginning.
 
Posts: 59
Karma: 10
Join Date: Jan 2011
Device: Kindle 1st Gen, Kindle 3 SO
Ok, fixed it. Amazing what the placement of a couple of lines can do...

Code:
class TriCityHeraldRecipe(BasicNewsRecipe):
    title          = u'Tri-City Herald'
    description    = 'The Tri-City Herald Mid-Columbia.'
    __author__     = 'Laura Gjovaag'
    oldest_article        = 1.5
    max_articles_per_feed = 100
    no_stylesheets        = True
    remove_javascript     = True
    keep_only_tags = [
                      dict(name='div', attrs={'id':'story_header'}),
                      dict(name='img', attrs={'class':'imageCycle'}),
                      dict(name='div', attrs={'id':['cycleImageCaption', 'story_body']})
                      ]
    remove_tags    = [
                      dict(name='div', attrs={'id':'story_mlt'}),
                      dict(name='a', attrs={'id':'commentCount'}),
                      dict(name=['script', 'noscript', 'style'])]
    extra_css      = 'h1{font: bold 140%;} #cycleImageCaption{font: monospace 60%}'

    feeds          = [
                      (u'Tri-City Herald Mid-Columbia', u'http://www.tri-cityherald.com/901/index.rss')
                     ]

And here's the one for the Yakima Herald-Republic...

Code:
class YakimaHeraldRepublicRecipe(BasicNewsRecipe):
    title          = u'Yakima Herald-Republic'
    description    = 'The Yakima Herald-Republic.'
    __author__     = 'Laura Gjovaag'
    oldest_article        = 1.5
    max_articles_per_feed = 100
    no_stylesheets        = True
    remove_javascript     = True
    keep_only_tags = [
                      dict(name='div', attrs={'id':['searchleft', 'headline_credit']}),
                      dict(name='div', attrs={'class':['photo', 'cauthor', 'photocredit']}),
                      dict(name='div', attrs={'id':['content_body', 'footerleft']})
                      ]
    extra_css = '.cauthor {font: monospace 60%;} .photocredit {font: monospace 60%}'

    feeds          = [
                      (u'Yakima Herald Online', u'http://feeds.feedburner.com/yhronlinenews'), 
                     ]
Tegan is offline   Reply With Quote
Advert
Old 01-13-2011, 10:59 PM   #6
Tegan
Connoisseur
Tegan began at the beginning.
 
Posts: 59
Karma: 10
Join Date: Jan 2011
Device: Kindle 1st Gen, Kindle 3 SO
I've found some code that is used to rotate images just like I described, over in this thread: https://www.mobileread.com/forums/sho...postcount=2263

But can it be applied to gocomics or comics.com recipes? I honestly can't parse it. Can anyone explain the recipe in that post to me?
Tegan is offline   Reply With Quote
Old 01-17-2011, 11:43 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 Tegan View Post
I've found some code that is used to rotate images just like I described, over in this thread: https://www.mobileread.com/forums/sho...postcount=2263

But can it be applied to gocomics or comics.com recipes? I honestly can't parse it. Can anyone explain the recipe in that post to me?
I wrote those two comic recipes. If your question is about them, feel free to ask. The link you've posted goes to some older code that I'm familiar with, but which used PythonMagickWand to do the image manipulation. It won't work anymore, as written, but worked fine originally in all comics and image-based recipes. You'll have to ask Kovid exactly what happened to PythonMagickWand and what can substitute for it.

I just rotate my reader from portrait to landscape and the G-sensor redoes the image. The CSS for images in those recipes is set to make the width equal to the max width of the device.
Starson17 is offline   Reply With Quote
Old 01-17-2011, 11:54 AM   #8
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: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
python magick wand was replaced by calibre.utils.magick and calibre.utils.magick.draw
kovidgoyal is offline   Reply With Quote
Old 01-17-2011, 02:28 PM   #9
Tegan
Connoisseur
Tegan began at the beginning.
 
Posts: 59
Karma: 10
Join Date: Jan 2011
Device: Kindle 1st Gen, Kindle 3 SO
Quote:
Originally Posted by Starson17 View Post
I just rotate my reader from portrait to landscape and the G-sensor redoes the image. The CSS for images in those recipes is set to make the width equal to the max width of the device.
Yeah, I've got a Kindle 1, so rotation of the reader itself doesn't do anything.

I just am trying to learn the code for the recipes by taking apart old code and trying to figure it out, while in the meantime making the recipes work better for me. I understand the bit about rotation, but I still haven't quite worked out what the lambda call does.

My understanding of that code is that it calls the graphic editor (Magick Wand) which Kovid points out has been replaced with a new call. Ok, got that. Then it does the postprocess to rotate the image. I understand the gist of it, but I'm an English grad, not a programmer, so I'm not sure what each bit is doing and searches aren't yielding much help.

Line by line:

Code:
for tag in soup.findAll(lambda tag: tag.name.lower()=='img' and tag.has_key('src')):
This is the bit that confuses me most. Is there a beginners guide to soup? What is the lambda? If someone can help me with that, maybe I can figure it out for myself.

Code:
 with pw.ImageMagick():
                img = pw.NewMagickWand()
                p = pw.NewPixelWand()
Ok, this is calling the image editor? How would that change with the new names? Where does one find the names of the Magick calls?

Code:
width = pw.MagickGetImageWidth(img)
                height = pw.MagickGetImageHeight(img)
                if( width > height ) :
                    print 'Rotate image'
                    pw.MagickRotateImage(img, p, 90)
                if not pw.MagickWriteImage(img, iurl):
                    raise RuntimeError('Failed to save image to %s'%iurl)
                pw.DestroyMagickWand(img)
                for divtag in soup.findAll('div'):
                   del(divtag['style'])
        return soup
Same here. I see a bunch of different calls to the image editor, but I can't find any documentation on how those calls should be phrased in the recipe. I've been Googling like mad, and still can't figure out some of the basics. I think there is a level of programming that I'm missing.

Can this bit of code be rewritten to apply to the current GoComics and Comics.com recipes so they will be automagically rotated for me? I'd be delighted if so. It would keep me from having to squint at the comics every day.
Tegan is offline   Reply With Quote
Old 01-17-2011, 03:26 PM   #10
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 Tegan View Post
I still haven't quite worked out what the lambda call does.
Python supports the creation of anonymous functions (i.e. functions that are not bound to a name), using the "lambda" construct.

Quote:
Line by line:

Code:
for tag in soup.findAll(lambda tag: tag.name.lower()=='img' and tag.has_key('src')):
This is the bit that confuses me most.
Simple - it finds img tags (convert to lower case first and compare tag name to "img") that have a key of "src."

Quote:
Is there a beginners guide to soup?
http://www.crummy.com/software/Beaut...mentation.html

Quote:
How would that change with the new names? Where does one find the names of the Magick calls?
We'll have to let Kovid answer that or point us to documentation.

Quote:
I see a bunch of different calls to the image editor, but I can't find any documentation on how those calls should be phrased in the recipe. I've been Googling like mad, and still can't figure out some of the basics. I think there is a level of programming that I'm missing.
All that's needed are the Magick calls that read the img, tell us the height and width for the compare, rotate the image if needed, and write it back.

Quote:
Can this bit of code be rewritten to apply to the current GoComics and Comics.com recipes so they will be automagically rotated for me?
Yes, provided that the image rotate function is available. I haven't had a chance to go Googling on this.
Starson17 is offline   Reply With Quote
Old 01-17-2011, 03:39 PM   #11
Tegan
Connoisseur
Tegan began at the beginning.
 
Posts: 59
Karma: 10
Join Date: Jan 2011
Device: Kindle 1st Gen, Kindle 3 SO
Quote:
Originally Posted by Starson17 View Post
Python supports the creation of anonymous functions (i.e. functions that are not bound to a name), using the "lambda" construct.
Googling it. I was thinking it was something entirely different, and now you've got me on the right path. Thank you!

Quote:
Originally Posted by Starson17 View Post
This should help. Again, thank you!

Quote:
Originally Posted by Starson17 View Post
We'll have to let Kovid answer that or point us to documentation.
Something like this: http://calibre.sourcearchive.com/doc...4190f4fa7.html
Or is that just the source code? I need documentation, but I don't want to pull Kovid away from improving his program to write up stuff to help people like me.

In any case, thank you for answering. You've set me on the right path to figuring it out.
Tegan is offline   Reply With Quote
Old 01-17-2011, 04:18 PM   #12
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: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Just look at the file comic/input.py for an example of using the new ImageMagick interface. It includes code to rotate/resize images.
kovidgoyal is offline   Reply With Quote
Old 01-18-2011, 10:45 AM   #13
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
Thanks to Kovid.
I rewrote the image rotation code. It's here in the sticky reusable code thread:

https://www.mobileread.com/forums/sho...7&postcount=15

If you use it in my comics recipes, remember that you will need to control image sizing with extra CSS. The current recipes set image width to 100%. You may wish to change it to set image height to 100% as this code will always have the longer image dimension set vertically.
Starson17 is offline   Reply With Quote
Old 01-18-2011, 07:31 PM   #14
Tegan
Connoisseur
Tegan began at the beginning.
 
Posts: 59
Karma: 10
Join Date: Jan 2011
Device: Kindle 1st Gen, Kindle 3 SO
Quote:
Originally Posted by Starson17 View Post
Thanks to Kovid.
I rewrote the image rotation code.
Can't seem to get it to work. I always end up with no images in the final product. Once I have a little time I'll try to troubleshoot it.
Tegan is offline   Reply With Quote
Old 01-19-2011, 09:33 AM   #15
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 Tegan View Post
Can't seem to get it to work. I always end up with no images in the final product. Once I have a little time I'll try to troubleshoot it.
Post your recipe if you need help. It works for me. I tested in the Explosm recipe (at your original link) for which that code was originally designed, but it should work in others.
Starson17 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Request for recipes: Cyanide and Happiness , SMBC bluewolf8 Recipes 5 01-02-2011 01:06 PM
Request for recipes of sites with no rss PipSqueak Recipes 1 10-16-2010 10:05 PM
Request for recipes mccande Calibre 4 12-26-2008 01:05 AM
Request for Recipes GPThomson Calibre 2 11-21-2008 12:19 PM
Request for Recipes girlperson1 Calibre 4 11-12-2008 03:25 PM


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


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