![]() |
#16 | |
Connoisseur
![]() Posts: 63
Karma: 46
Join Date: Feb 2011
Device: Kindle 3 (cracked screen!); PW1; Oasis
|
Quote:
I also built the e-book under Ubuntu Linux to see if the problem was specific to Windows. The same "diamond" invalid characters appeared, but the e-book in this case did not crash the Calibre reader. The images however were not visible in the e-book in the Calibre reader, whereas they were visible in the MobiPocket Reader under Windows. Code:
from calibre.web.feeds.news import BasicNewsRecipe from calibre.ebooks.BeautifulSoup import Tag, NavigableString class thai(BasicNewsRecipe): title = u'thai' __author__ = u'oneillpt' #masthead_url = 'http://www.elpais.com/im/tit_logo_int.gif' INDEX = 'http://www.naewna.com/allnews.asp?ID=79' language = 'th' #remove_tags_before = dict(name='div', attrs={'class':'estructura_2col'}) #keep_tags = [dict(name='div', attrs={'class':'estructura_2col'})] #remove_tags = [dict(name='div', attrs={'class':'votos estirar'}), #dict(name='div', attrs={'id':'utilidades'}), #dict(name='div', attrs={'class':'info_relacionada'}), #dict(name='div', attrs={'class':'mod_apoyo'}), #dict(name='div', attrs={'class':'contorno_f'}), #dict(name='div', attrs={'class':'pestanias'}), #dict(name='div', attrs={'class':'otros_webs'}), #dict(name='div', attrs={'id':'pie'}) #] no_stylesheets = True remove_javascript = True def parse_index(self): articles = [] soup = self.index_to_soup(self.INDEX) cover = None feeds = [] for section in soup.findAll('body'): section_title = self.tag_to_string(section.find('h1')) z = section.find('td', attrs={'background':'images/fa04.gif'}) self.log('z', z) x = z.find('font') self.log('x', x) y = x.find('strong') self.log('y', y) section_title = self.tag_to_string(y) self.log('section_title(1): ', section_title) if section_title == "": section_title = u'Thai Feed' self.log('section_title(2): ', section_title) articles = [] for post in section.findAll('a', href=True): self.log('--> p: ', post) url = post['href'] self.log('--> u: ', url) if url.startswith('n'): url = 'http://www.naewna.com/'+url self.log('--> u: ', url) title = self.tag_to_string(post) self.log('--> t: ', title) if str(post).find('class="style4 style15"') > 0: klass = post['class'] self.log('--> k: ', klass) if klass == "style4 style15": self.log() self.log('--> post: ', post) self.log('--> url: ', url) self.log('--> title: ', title) self.log('--> class: ', klass) articles.append({'title':title, 'url':url}) if articles: feeds.append((section_title, articles)) return feeds |
|
![]() |
![]() |
![]() |
#17 |
Connoisseur
![]() Posts: 63
Karma: 46
Join Date: Feb 2011
Device: Kindle 3 (cracked screen!); PW1; Oasis
|
I'm now fairly sure that the source encoding is the problem. I saved the source of the index page and of the first two links followed, then converted these Windows-874 files to UTF-8, edited INDEX in the recipe to point to the local UTF-8 converted copy, and edited the links in the index page to point to the local UTF-8 converted copies for the two links copied.
I've attached the epub and mobi versions of the e-book built for you to check. The text now looks Thai to me! |
![]() |
![]() |
![]() |
#18 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() Posts: 475
Karma: 590
Join Date: Aug 2009
Location: Bangkok, Thailand
Device: Kindle Paperwhite
|
Hi oneillpt,
Just try your latest script, Calibre got the content without error. As you said, Calibre will crash when trying to open the content. I don't know why they are still using 874 codepage, instead of others which are more popular. The thai.mobi/epub display Thai correctly. Thanks again for your kind help. |
![]() |
![]() |
![]() |
#19 | |
Connoisseur
![]() Posts: 63
Karma: 46
Join Date: Feb 2011
Device: Kindle 3 (cracked screen!); PW1; Oasis
|
Quote:
So the recipe now starts with: Code:
from calibre.web.feeds.news import BasicNewsRecipe from calibre.ebooks.BeautifulSoup import Tag, NavigableString class thai(BasicNewsRecipe): title = u'thai' __author__ = u'oneillpt' #masthead_url = 'http://www.elpais.com/im/tit_logo_int.gif' # (you may want to select a masthead image from your source here) INDEX = 'http://www.naewna.com/allnews.asp?ID=79' encoding = 'cp874' language = 'th_TH' oldest_article = 7 max_articles_per_feed = 2 |
|
![]() |
![]() |
![]() |
#20 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() Posts: 475
Karma: 590
Join Date: Aug 2009
Location: Bangkok, Thailand
Device: Kindle Paperwhite
|
Wow...thanks a lot. Let me try tonight.
|
![]() |
![]() |
![]() |
#21 |
Member
![]() Posts: 20
Karma: 10
Join Date: Jul 2011
Device: Sony PRS 350
|
oneillpt thank you ENORMOUSLY for your tutorial! It was the perfect intro to recipe building - nice and simple code, instructions step by step. Your guide fills the gap for noobs' first steps trying to learn Python, Soup and recipe building at the same time. I was hopeless at getting anything to work until I found your tips- now got mine working!
|
![]() |
![]() |
![]() |
#22 |
Member
![]() Posts: 15
Karma: 10
Join Date: Apr 2011
Device: Kindle
|
Thumbs up to oneillpt! You guys that are 100% programmers don't understand how useful the commented code is.
|
![]() |
![]() |
![]() |
#23 |
Member
![]() Posts: 22
Karma: 20
Join Date: Aug 2011
Device: Kindle 3
|
Hello community,
I need some help solving the problem on the thread: https://www.mobileread.com/forums/sho...d.php?t=146324 someone? |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Is there a good way to convert partial rss to full rss feeds. | Zorz | Other formats | 5 | 05-29-2010 12:17 PM |
RSS Feed | timezone | Feedback | 8 | 01-02-2010 06:55 PM |
RSS Feed Newspaper without Calibre | ggareau | Sony Reader | 4 | 07-30-2009 01:06 AM |
RSS Feed Updates | Alexander Turcic | Announcements | 0 | 06-11-2004 04:11 PM |