Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 07-22-2009, 08:32 AM   #1
mairabc
Junior Member
mairabc began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Jul 2009
Device: BeBook
Reversing articles order in a custom news recipe?

Hello,

first of all, thank you for the wonderful software! Calibre is great, I love it!

I tried to understand the API and looked for something in the forum that would point in the direction I wanted, but with no luck. But in any case, I am sorry if this is already explained somewhere and I missed it.

Now, to the question:

I tried to create a News Source from a website that posts every day a new chapter of a detective story. So, it makes sense to me to have the posts ordered from oldest to newest, and have each post as a chapter of a book. I am pretty sure I can achieve what I want using a custom recipe in Python, but I couldn't find out how. Which method should I modify to get the articles in reverse order in the index?

Any help is highly appreciated

Best,
Maira
mairabc is offline   Reply With Quote
Old 07-22-2009, 10:00 AM   #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: 25,400
Karma: 4961459
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You would have to re-implement the parse_feeds method in your recipe. Have a look at the original in BasicNewsRecipe, should be failrly obvious how to modify it.
kovidgoyal is offline   Reply With Quote
Old 11-26-2009, 09:38 AM   #3
JayCeeEll
Connoisseur
JayCeeEll doesn't litterJayCeeEll doesn't litterJayCeeEll doesn't litter
 
JayCeeEll's Avatar
 
Posts: 87
Karma: 204
Join Date: Dec 2007
Location: Exeter, Devon, UK
Device: PRS-300
I have been playing around with trying to do this and I think that I need to reverse the entries within the feed.

As far as I can tell the best place to do this would be populate_from_feed in __init__.py from web.feeds

Currently populate_from_feed is:
PHP Code:
    def populate_from_feed(selffeedtitle=Noneoldest_article=7,
                           
max_articles_per_feed=100):
        
entries feed.entries
        feed 
feed.feed
        self
.title        feed.get('title'_('Unknown feed')) if not title else title
        self
.description  feed.get('description''')
        
image             feed.get('image', {})
        
self.image_url    image.get('href'None)
        
self.image_width  image.get('width'88)
        
self.image_height image.get('height'31)
        
self.image_alt    image.get('title''')

        
self.articles = []
        
self.id_counter 0
        self
.added_articles = []

        
self.oldest_article oldest_article

        
for item in entries:
            if 
len(self.articles) >= max_articles_per_feed:
                break
            
self.parse_article(item
I have tried adding entries.reverse before the for item in entries but this does not work.

In VB I could just replace the for with a loop from entries.count -1 to 0, but I am not sure how to do this in Python.

Any suggestions?
JayCeeEll is offline   Reply With Quote
Old 11-26-2009, 10: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: 25,400
Karma: 4961459
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Code:
for item in reversed(entries):
kovidgoyal is offline   Reply With Quote
Old 11-27-2009, 03:56 PM   #5
JayCeeEll
Connoisseur
JayCeeEll doesn't litterJayCeeEll doesn't litterJayCeeEll doesn't litter
 
JayCeeEll's Avatar
 
Posts: 87
Karma: 204
Join Date: Dec 2007
Location: Exeter, Devon, UK
Device: PRS-300
I have created a new ticket #4095 which includes a bazaar patch file to allow this behavior.

If the patch gets included in calibre then adding "reverse_article_order = True" to a custom recipe will reverse the article order in the output file.

Next I need to figure out how calibre loads/saves data from the SQLite database so that I can include a new field on the news table and only include articles in the output if they are later than the current article stored in the DB.
JayCeeEll is offline   Reply With Quote
Old 12-12-2009, 05:24 PM   #6
mtg
Junior Member
mtg began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Mar 2008
Device: Kindle 2
When I try using "reverse_article_order = True", I get the following exception on both Mac Leopard and Windows XP:

InputFormatPlugin: Recipe Input running Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Applications/calibre.app/Contents/console.app/Contents/Resources/lib/python2.6/site-packages.zip/calibre/utils/ipc/worker.py", line 90, in main
File "calibre/gui2/convert/gui_conversion.pyo", line 21, in gui_convert
File "calibre/ebooks/conversion/plumber.pyo", line 736, in run
File "calibre/customize/conversion.pyo", line 208, in __call__
File "calibre/web/feeds/input.pyo", line 80, in convert
File "calibre/web/feeds/news.pyo", line 598, in download
File "calibre/web/feeds/news.pyo", line 742, in build_index
TypeError: argument to reversed() must be a sequence

I set up a development environment on my Mac, but when I try to modify the code in news.py, it appears that it always runs the compiled app code rather than the code from the source tree, so I haven't been able to debug it. Is there a way to make workers run the code in the source tree rather than the compiled code in the app?
mtg is offline   Reply With Quote
Reply

Tags
custom news source, python

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help regarding custom recipe gagsays Calibre 3 05-26-2010 07:48 PM
Custom Recipe for CNBC Magazine nittecat Calibre 1 02-28-2010 04:14 AM
Custom Recipe CABITSS Introduce Yourself 2 09-22-2009 10:30 AM
Custom Recipe CABITSS Calibre 3 09-22-2009 10:29 AM
A problem with custom recipe joshdu1125 Calibre 1 05-03-2009 09:31 PM


All times are GMT -4. The time now is 02:38 PM.


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