![]() |
#1 |
Connoisseur
![]() 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. |
![]() |
![]() |
![]() |
#2 |
Connoisseur
![]() 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. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Connoisseur
![]() 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') ] |
![]() |
![]() |
![]() |
#4 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,185
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
The postprocess_html method is what you're looking for.
|
![]() |
![]() |
![]() |
#5 |
Connoisseur
![]() 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'), ] |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Connoisseur
![]() 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? |
![]() |
![]() |
![]() |
#7 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Quote:
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. |
|
![]() |
![]() |
![]() |
#8 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,185
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
python magick wand was replaced by calibre.utils.magick and calibre.utils.magick.draw
|
![]() |
![]() |
![]() |
#9 | |
Connoisseur
![]() Posts: 59
Karma: 10
Join Date: Jan 2011
Device: Kindle 1st Gen, Kindle 3 SO
|
Quote:
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')): Code:
with pw.ImageMagick(): img = pw.NewMagickWand() p = pw.NewPixelWand() 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 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. |
|
![]() |
![]() |
![]() |
#10 | |||||
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Python supports the creation of anonymous functions (i.e. functions that are not bound to a name), using the "lambda" construct.
Quote:
Quote:
Quote:
Quote:
Quote:
|
|||||
![]() |
![]() |
![]() |
#11 | |||
Connoisseur
![]() Posts: 59
Karma: 10
Join Date: Jan 2011
Device: Kindle 1st Gen, Kindle 3 SO
|
Quote:
Quote:
Quote:
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. |
|||
![]() |
![]() |
![]() |
#12 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,185
Karma: 27110894
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.
|
![]() |
![]() |
![]() |
#13 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#14 |
Connoisseur
![]() Posts: 59
Karma: 10
Join Date: Jan 2011
Device: Kindle 1st Gen, Kindle 3 SO
|
|
![]() |
![]() |
![]() |
#15 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
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.
|
![]() |
![]() |
![]() |
|
![]() |
||||
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 |