View Single Post
Old 07-19-2011, 10:06 PM   #21
oneillpt
Connoisseur
oneillpt began at the beginning.
 
Posts: 63
Karma: 46
Join Date: Feb 2011
Device: Kindle 3 (cracked screen!); PW1; Oasis
Quote:
Originally Posted by nickredding View Post
This is probably my last update on this. I have learned that Kindlegen 1.1 handles the masthead images properly as well as descriptions in the "Articles List" view. Why these features vanished with Kindlegen 1.2 I don't know but if you use Kindlegen 1.1 instead you can have them back and I recommend that.

...

As before, if you are updating from an earlier Calibre-Kindle, be sure to replace ALL the files in the folder. My thanks to veezh, tylau0, oneillpt and dwanthny for taking the time to help sort out the issues with the earlier versions--I think we have something stable now.
I have found a few issues still remaining, with solutions for some of these. I'll examine the changes in v1.5 to news-prefix.py (and possibly using kindlegen 1.1) later today to see if they resolve some issues I have found with particular custom recipes, and report on the results, but for now some small issues and solutions:

news.bat: recipes named with embedded blanks cause failure. For example,

news "The Irish Times" -verbose (using "The Irish Times.recipe")

I thought I had solved this, but I've overridden my news.bat, and need to redo the modifications, and have not succeeded yet. Copying the recipe with a new name without embedded blanks solves the problem of course.

update-recipe.py: Two problems may arise. Custom recipes created in Calibre (possibly only for certain versions) may use

class ...(AutomaticNewsRecipe): rather than class ...(BasicNewsRecipe):

(although Calibre 0.8.10 hides this when displaying the recipe, substituting BasicNewsRecipe, the custom recipe in C:\Users\Joe\AppData\Roaming\calibre\custom_recipe s retains AutomaticNewsRecipe unless the recipe is edited and resaved). If custom recipes are copied from ...\custom_recipes, update_recipe.py needs to check for either (BasicNewsRecipe): or (AutomaticNewsRecipe):

Further, custom recipes created in Calibre may start with class, and may not preceed this with any other lines such as "__license__ = 'GPL v3'" or "from calibre.web.feeds.news import BasicNewsRecipe", and in such cases, where the 'c' of class is the first character encountered, update-recipe.py fails.

Both these problems are corrected by the followings lines at the end of editRecipe in update-recipe.py:

Code:
pph_result = re.search(r'\s*def\s+postprocess_html[^(]*\([^)]*\)\s*:',infile_str,re.S|re.I)
        if pph_result:
                infile_str = re.sub(r'def\s+postprocess_html','def orig_postprocess_html',infile_str,re.S|re.I)
                pph_result = re.search(r'\s*def orig_postprocess_html[^(]*\([^)]*\)\s*:',infile_str,re.S|re.I)
                #news_result = re.search(r'\s*class[^(]+\(basicnewsrecipe\)\s*:',infile_str,re.S|re.I)
                news_result = re.search(r'\s*class[^(]+\(((automat)|(bas))icnewsrecipe\)\s*:',infile_str,re.S|re.I)
                if (news_result==None):
                        print "Cannot find news recipe class"
                        return
                if (news_result.start() > 0):
                        outfile_str = infile_str[:news_result.start()+1]+recipe_header_str+\
                              infile_str[news_result.start():news_result.end()+1]+news_prefix_str+\
                              infile_str[news_result.end():pph_result.start()+1]+postprocess_html_frag_str+\
                              infile_str[pph_result.end():]
                else:
                        outfile_str = recipe_header_str+\
                              infile_str[news_result.start():news_result.end()+1]+news_prefix_str+\
                              infile_str[news_result.end():pph_result.start()+1]+postprocess_html_frag_str+\
                              infile_str[pph_result.end():]
        else:
                #news_result = re.search(r'\s*class[^(]+\(basicnewsrecipe\)\s*:',infile_str,re.S|re.I)
                news_result = re.search(r'\s*class[^(]+\(((automat)|(bas))icnewsrecipe\)\s*:',infile_str,re.S|re.I)
                if (news_result==None):
                        print "Cannot find news recipe class"
                        return
                if (news_result.start() > 0):
                        outfile_str = infile_str[:news_result.start()+1]+recipe_header_str+\
                              infile_str[news_result.start():news_result.end()+1]+news_prefix_str+\
                              postprocess_html_str+infile_str[news_result.end():]
                else:
                        outfile_str = recipe_header_str+\
                              infile_str[news_result.start():news_result.end()+1]+news_prefix_str+\
                              postprocess_html_str+infile_str[news_result.end():]
        outfile.write(outfile_str)
        outfile.flush()
        outfile.close()
oneillpt is offline   Reply With Quote