02-05-2011, 03:39 PM | #1 |
Member
Posts: 15
Karma: 10
Join Date: Feb 2011
Device: Kindle 3G
|
including RSS item pubDate in ebook text
I just got a new Kindle yesterday and have been playing around to see how it's going to work with replacing my iPod for reading news and blogs. Calibre makes it pretty easy to stay up-to-date, but there is one thing that's bugging me and that's finding out when news items were posted in my RSS feeds. I am not interested in the whole feed's publication date - or the date that the ebook is generated - i would like to see each news item's publication date next to its title. I would like to see something like this:
Article Title posted 2011-02-04 11:30:23 Article text. Here is what i tried for a first attempt: Code:
def populate_article_metadata(self, article, soup, first): time = NavigableString(article.localtime.strftime("%Y-%m-%d %H:%M:%S")) p = Tag(soup, 'p') em = Tag(soup, 'em') soup.insert(0, p) p.insert(0, em) em.insert(0, time) I know i'm using this method for the opposite of what is intended - i'm updating the soup from the article rather than the article from the soup, but i thought it would still work. Unfortunately it doesn't. I even tried just inserting some static test text and it didn't work either, which leads me to believe that "soup" isn't a pointer to but a copy of the data that is used to create the ebook text. Is there any other way to access the article object so i can pull metadata out and put it into the ebook text (e.g. in postprocess_html)? On a side note, is there any way to quickly test a recipe from the command-line? It is pretty painful to click around the UI to do it every time something small gets changed. The command line would also be helpful for debug messages. I'm running Mac OS. Thanks everyone. |
02-05-2011, 04:04 PM | #2 |
Member
Posts: 15
Karma: 10
Join Date: Feb 2011
Device: Kindle 3G
|
Never mind that command-line request, found it
|
Advert | |
|
02-05-2011, 04:40 PM | #3 |
Member
Posts: 15
Karma: 10
Join Date: Feb 2011
Device: Kindle 3G
|
It seems i was totally overcomplicating the solution. Here is some code that works, for anyone wanting to do the same thing. Presumably you could also insert the RSS item's author here as well, which is useful for blogs with more than one contributor.
Code:
def populate_article_metadata(self, article, soup, first): h2 = soup.find('h2') h2.replaceWith(h2.prettify() + '<p><em>posted at ' + article.localtime.strftime('%Y-%m-%d %H:%M:%S') + '</em></p>') |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Please help with RSS feed text alignment / justification | zoilom | Recipes | 0 | 01-09-2011 12:23 PM |
eBook item on BBC site | alecE | News | 1 | 11-25-2010 07:39 AM |
UK Channel 4 news item on ebook piracy | garygibsonsf | News | 3 | 10-19-2009 07:25 AM |
Using PubDate in print_version of custom news source | mobilereader72 | Calibre | 4 | 05-30-2009 05:52 PM |
08:05 - BBC Radio 4 to ebook item in next hour | Sparrow | News | 5 | 08-07-2008 11:57 AM |