07-22-2009, 08:32 AM | #1 |
Junior Member
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 |
07-22-2009, 10:00 AM | #2 |
creator of calibre
Posts: 44,292
Karma: 23661992
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.
|
Advert | |
|
11-26-2009, 09:38 AM | #3 |
Connoisseur
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:
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? |
11-26-2009, 10:03 AM | #4 |
creator of calibre
Posts: 44,292
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Code:
for item in reversed(entries): |
11-27-2009, 03:56 PM | #5 |
Connoisseur
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. |
Advert | |
|
12-12-2009, 05:24 PM | #6 |
Junior Member
Posts: 8
Karma: 10
Join Date: Mar 2008
Device: iPod Touch (5th gen), 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? |
Tags |
custom news source, python |
|
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 |