home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_280 / utrinski.recipe < prev    next >
Text File  |  2011-09-09  |  3KB  |  72 lines

  1. #!/usr/bin/env  python
  2.  
  3. __license__   = 'GPL v3'
  4. __copyright__ = '2011, Darko Spasovski <darko.spasovski at gmail.com>'
  5. '''
  6. utrinski.com.mk
  7. '''
  8.  
  9. import re
  10. import datetime
  11. from calibre.web.feeds.news import BasicNewsRecipe
  12.  
  13. class UtrinskiVesnik(BasicNewsRecipe):
  14.  
  15.     __author__            = 'Darko Spasovski'
  16.     INDEX                 = 'http://www.utrinski.com.mk/'
  17.     title                 = 'Utrinski Vesnik'
  18.     description           = 'Daily Macedonian newspaper'
  19.     masthead_url          = 'http://www.utrinski.com.mk/images/LogoTop.jpg'
  20.     language              = 'mk'
  21.     remove_javascript     = True
  22.     publication_type      = 'newspaper'
  23.     category              = 'news, Macedonia'
  24.     oldest_article        = 2
  25.     max_articles_per_feed = 100
  26.     no_stylesheets        = True
  27.     use_embedded_content  = False
  28.     preprocess_regexps    = [(re.compile(i[0], re.IGNORECASE | re.DOTALL), i[1]) for i in
  29.     [
  30.         ## Remove anything before the start of the article.
  31.         (r'<body.*?Article start-->', lambda match: '<body>'),
  32.  
  33.         ## Remove anything after the end of the article.
  34.         (r'<!--Article end.*?</body>', lambda match : '</body>'),
  35.         ]
  36.     ]
  37.     extra_css             = """
  38.                                 body{font-family: Arial,Helvetica,sans-serif}
  39.                                 .WB_UTRINSKIVESNIK_Naslov{FONT-WEIGHT: bold; FONT-SIZE: 18px; FONT-FAMILY: Arial, Verdana, Tahoma; TEXT-DECORATION: none}
  40.                             """
  41.  
  42.     conversion_options = {
  43.                           'comment'  : description,
  44.                           'tags'     : category,
  45.                           'language' : language,
  46.                           'linearize_tables' : True
  47.                         }
  48.  
  49.     def parse_index(self):
  50.         soup = self.index_to_soup(self.INDEX)
  51.         feeds = []
  52.         for section in soup.findAll('a', attrs={'class':'WB_UTRINSKIVESNIK_TOCTitleBig'}):
  53.             sectionTitle = section.contents[0].string
  54.             tocItemTable = section.findAllPrevious('table')[1]
  55.             if tocItemTable is None: continue
  56.             articles = []
  57.             while True:
  58.                 tocItemTable = tocItemTable.nextSibling
  59.                 if tocItemTable is None: break
  60.                 article = tocItemTable.findAll('a', attrs={'class': 'WB_UTRINSKIVESNIK_TocItem'})
  61.                 if len(article)==0: break
  62.                 title = self.tag_to_string(article[0], use_alt=True).strip()
  63.                 articles.append({'title': title, 'url':'http://www.utrinski.com.mk/' + article[0]['href'], 'description':'', 'date':''})
  64.             if articles:
  65.                 feeds.append((sectionTitle, articles))
  66.         return feeds
  67.  
  68.  
  69.     def get_cover_url(self):
  70.         datum = datetime.datetime.today().strftime('%d_%m_%Y')
  71.         return 'http://www.utrinski.com.mk/WBStorage/Files/' + datum + '.jpg'
  72.