home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_4193 < prev    next >
Encoding:
Text File  |  2010-10-25  |  3.0 KB  |  65 lines

  1. cense__   = 'GPL v3'
  2. __copyright__ = '2010, Eddie Lau'
  3. '''
  4. modified from Singtao Toronto calibre recipe by rty
  5. '''
  6.  
  7. import datetime
  8. from calibre.web.feeds.recipes import BasicNewsRecipe
  9.  
  10. class AdvancedUserRecipe1278063072(BasicNewsRecipe):
  11.     title          = 'Ming Pao - Hong Kong'
  12.     oldest_article = 1
  13.     max_articles_per_feed = 100
  14.     __author__            = 'Eddie Lau'
  15.     description           = 'Hong Kong Chinese Newspaper'
  16.     publisher             = 'news.mingpao.com'
  17.     category              = 'Chinese, News, Hong Kong'
  18.     remove_javascript = True
  19.     use_embedded_content   = False
  20.     no_stylesheets = True
  21.     language = 'zh'
  22.     encoding = 'Big5-HKSCS'
  23.     recursions = 0
  24.     conversion_options = {'linearize_tables':True}
  25.     masthead_url = 'http://news.mingpao.com/image/portals_top_logo_news.gif'
  26.  
  27.     keep_only_tags = [dict(name='h1'),
  28.                       dict(attrs={'id':['newscontent01','newscontent02']})]
  29.  
  30.     def get_fetchdate(self):
  31.         dt_utc = datetime.datetime.utcnow()
  32.         # convert UTC to local hk time
  33.         dt_local = dt_utc - datetime.timedelta(-8.0/24)
  34.         return dt_local.strftime("%Y%m%d")
  35.  
  36.     def parse_index(self):
  37.             feeds = []
  38.             dateStr = self.get_fetchdate()
  39.             for title, url in [(u'\u8981\u805e Headline', 'http://news.mingpao.com/' + dateStr + '/gaindex.htm'), (u'\u6559\u80b2 Education', 'http://news.mingpao.com/' + dateStr + '/gfindex.htm'), (u'\u6e2f\u805e Local', 'http://news.mingpao.com/' + dateStr + '/gbindex.htm'), (u'\u793e\u8a55\u2027\u7b46\u9663 Editorial', 'http://news.mingpao.com/' + dateStr + '/mrindex.htm'), (u'\u8ad6\u58c7 Forum', 'http://news.mingpao.com/' + dateStr + '/faindex.htm'), (u'\u4e2d\u570b China', 'http://news.mingpao.com/' + dateStr + '/caindex.htm'), (u'\u570b\u969b World', 'http://news.mingpao.com/' + dateStr + '/taindex.htm'), ('Tech News', 'http://news.mingpao.com/' + dateStr + '/naindex.htm'), (u'\u9ad4\u80b2 Sport', 'http://news.mingpao.com/' + dateStr + '/spindex.htm'), (u'\u526f\u520a Supplement', 'http://news.mingpao.com/' + dateStr + '/jaindex.htm'),]:
  40.                 articles = self.parse_section(url)
  41.                 if articles:
  42.                     feeds.append((title, articles))
  43.             return feeds
  44.  
  45.     def parse_section(self, url):
  46.             dateStr = self.get_fetchdate()
  47.             soup = self.index_to_soup(url)
  48.             divs = soup.findAll(attrs={'class': ['bullet']})
  49.             current_articles = []
  50.             for i in divs:
  51.                 a = i.find('a', href = True)
  52.                 title = self.tag_to_string(a)
  53.                 url = a.get('href', False)
  54.                 url = 'http://news.mingpao.com/' + dateStr + '/' +url
  55.                 current_articles.append({'title': title, 'url': url, 'description':''})
  56.             return current_articles
  57.  
  58.     def preprocess_html(self, soup):
  59.         for item in soup.findAll(style=True):
  60.            del item['style']
  61.         for item in soup.findAll(width=True):
  62.            del item['width']
  63.         return soup
  64.  
  65.