diff --git a/resources/recipes/bbc_chinese.recipe b/resources/recipes/bbc_chinese.recipe new file mode 100644 index 0000000000..e2bff81b90 --- /dev/null +++ b/resources/recipes/bbc_chinese.recipe @@ -0,0 +1,39 @@ +from calibre.web.feeds.news import BasicNewsRecipe + +class AdvancedUserRecipe1277443634(BasicNewsRecipe): + title = u'BBC Chinese' + oldest_article = 7 + max_articles_per_feed = 100 + + feeds = [ + (u'\u4e3b\u9875', u'http://www.bbc.co.uk/zhongwen/simp/index.xml'), + (u'\u56fd\u9645\u65b0\u95fb', u'http://www.bbc.co.uk/zhongwen/simp/world/index.xml'), + (u'\u4e24\u5cb8\u4e09\u5730', u'http://www.bbc.co.uk/zhongwen/simp/china/index.xml'), + (u'\u91d1\u878d\u8d22\u7ecf', u'http://www.bbc.co.uk/zhongwen/simp/business/index.xml'), + (u'\u7f51\u4e0a\u4e92\u52a8', u'http://www.bbc.co.uk/zhongwen/simp/interactive/index.xml'), + (u'\u97f3\u89c6\u56fe\u7247', u'http://www.bbc.co.uk/zhongwen/simp/multimedia/index.xml'), + (u'\u5206\u6790\u8bc4\u8bba', u'http://www.bbc.co.uk/zhongwen/simp/indepth/index.xml') + ] + extra_css = ''' + @font-face {font-family: "DroidFont", serif, sans-serif; src: url(res:///system/fonts/DroidSansFallback.ttf); }\n + body {margin-right: 8pt; font-family: 'DroidFont', serif;}\n + h1 {font-family: 'DroidFont', serif;}\n + .articledescription {font-family: 'DroidFont', serif;} + ''' + __author__ = 'rty' + __version__ = '1.0' + language = 'zh' + pubisher = 'British Broadcasting Corporation' + description = 'BBC news in Chinese' + category = 'News, Chinese' + remove_javascript = True + use_embedded_content = False + no_stylesheets = True + encoding = 'UTF-8' + conversion_options = {'linearize_tables':True} + masthead_url = 'http://wscdn.bbc.co.uk/zhongwen/simp/images/1024/brand.jpg' + keep_only_tags = [ + dict(name='h1'), + dict(name='p', attrs={'class':['primary-topic','summary']}), + dict(name='div', attrs={'class':['bodytext','datestamp']}), + ] diff --git a/resources/recipes/singtao_daily.recipe b/resources/recipes/singtao_daily.recipe new file mode 100644 index 0000000000..bb5280c062 --- /dev/null +++ b/resources/recipes/singtao_daily.recipe @@ -0,0 +1,73 @@ +from calibre.web.feeds.recipes import BasicNewsRecipe + +class AdvancedUserRecipe1278063072(BasicNewsRecipe): + title = u'Singtao Daily - Canada' + oldest_article = 7 + max_articles_per_feed = 100 + __author__ = 'rty' + description = 'Toronto Canada Chinese Newspaper' + publisher = 'news.singtao.ca' + category = 'Chinese, News, Canada' + remove_javascript = True + use_embedded_content = False + no_stylesheets = True + language = 'zh' + conversion_options = {'linearize_tables':True} + masthead_url = 'http://news.singtao.ca/i/site_2009/logo.jpg' + extra_css = ''' + @font-face {font-family: "DroidFont", serif, sans-serif; src: url(res:///system/fonts/DroidSansFallback.ttf); }\ + + body {text-align: justify; margin-right: 8pt; font-family: 'DroidFont', serif;}\ + + h1 {font-family: 'DroidFont', serif;}\ + + .articledescription {font-family: 'DroidFont', serif;} + ''' + keep_only_tags = [ + dict(name='div', attrs={'id':['title','storybody']}), + dict(name='div', attrs={'class':'content'}) + ] + + def parse_index(self): + feeds = [] + for title, url in [ + ('Editorial', 'http://news.singtao.ca/toronto/editorial.html'), + ('Toronto \xe5\x9f\x8e\xe5\xb8\x82/\xe7\xa4\xbe\xe5\x8d\x80', 'http://news.singtao.ca/toronto/city.html'), + ('Canada \xe5\x8a\xa0\xe5\x9c\x8b', 'http://news.singtao.ca/toronto/canada.html'), + ('Entertainment', 'http://news.singtao.ca/toronto/entertainment.html'), + ('World', 'http://news.singtao.ca/toronto/world.html'), + ('Finance \xe5\x9c\x8b\xe9\x9a\x9b\xe8\xb2\xa1\xe7\xb6\x93', 'http://news.singtao.ca/toronto/finance.html'), + ('Sports', 'http://news.singtao.ca/toronto/sports.html'), + ]: + articles = self.parse_section(url) + if articles: + feeds.append((title, articles)) + return feeds + + def parse_section(self, url): + soup = self.index_to_soup(url) + div = soup.find(attrs={'class': ['newslist paddingL10T10','newslist3 paddingL10T10']}) + #date = div.find(attrs={'class': 'underlineBLK'}) + current_articles = [] + for li in div.findAll('li'): + a = li.find('a', href = True) + if a is None: + continue + title = self.tag_to_string(a) + url = a.get('href', False) + if not url or not title: + continue + if url.startswith('/'): + url = 'http://news.singtao.ca'+url + # self.log('\ \ Found article:', title) + # self.log('\ \ \ ', url) + current_articles.append({'title': title, 'url': url, 'description':''}) + + return current_articles + + def preprocess_html(self, soup): + for item in soup.findAll(style=True): + del item['style'] + for item in soup.findAll(width=True): + del item['width'] + return soup diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 09c1f8478b..9d85dce075 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -501,8 +501,9 @@ class DeviceBooksView(BooksView): # {{{ def contextMenuEvent(self, event): self.edit_collections_menu.setVisible( - self._model.db.supports_collections() and \ - prefs['preserve_user_collections']) + callable(getattr(self._model.db, 'supports_collections', None)) and \ + self._model.db.supports_collections() and \ + prefs['preserve_user_collections']) self.context_menu.popup(event.globalPos()) event.accept()