Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Recipes

Notices

Reply
 
Thread Tools Search this Thread
Old 10-08-2010, 10:18 PM   #1
jefferson_frantz
Member
jefferson_frantz began at the beginning.
 
jefferson_frantz's Avatar
 
Posts: 14
Karma: 12
Join Date: Jan 2009
Location: Lima, Perú
Device: Kindle 2 and Sony Reader PRS 505
New Recipe for Revista El Cultural(Spain)

Here is a recipe for spanish magazine 'El Cultural'

Spoiler:

Code:
from calibre.web.feeds.recipes import BasicNewsRecipe
from BeautifulSoup import BeautifulSoup, Tag

class RevistaElCultural(BasicNewsRecipe):

    title       = 'Revista El Cultural'
    __author__  = 'Jefferson Frantz'
    description = 'Revista de cultura'
    timefmt = ' [%d %b, %Y]'
    language = 'es_ES'

    no_stylesheets = True
    remove_javascript = True

    extra_css              = 'h1{ font-family: sans-serif; font-size: large; font-weight: bolder; text-align: justify } h2{ font-family: sans-serif; font-size: small; font-weight: 500; text-align: justify } h3{ font-family: sans-serif; font-size: small; font-weight: 500; text-align: justify } h4{ font-family: sans-serif; font-weight: lighter; font-size: medium; font-style: italic; text-align: justify } .rtsArticuloFirma{ font-family: sans-serif; font-size: small; text-align: justify } .column span-13 last{ font-family: sans-serif; font-size: medium; text-align: justify } .rtsImgArticulo{font-family: serif; font-size: small; color: #000000; text-align: justify}'


    def preprocess_html(self, soup):
            for item in soup.findAll(style=True):
               del item['style']

            return soup

    keep_only_tags = [dict(name='div', attrs={'class':['column span-13 last']}),dict(name='div', attrs={'class':['rtsImgArticulo']})]

    remove_tags        = [
                             dict(name=['object','link','script','ul'])
                            ,dict(name='div', attrs={'class':['rtsRating']})

                         ]


    #TO GET ARTICLES IN SECTION
    def ec_parse_section(self, url, titleSection):
            print 'Section: '+ titleSection
            soup = self.index_to_soup(url)
            div = soup.find(attrs={'id':'gallery'})
            current_articles = []
            
            for a in div.findAllNext('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 not url.startswith('/version_papel/'+titleSection+'/'):
                        if len(current_articles) > 0 and not url.startswith('/secciones/'):
                            break
                        continue

                    if url.startswith('/version_papel/'+titleSection+'/'):
                         url = 'http://www.elcultural.es'+url

                    self.log('\t\tFound article:', title[0:title.find("|")-1])
                    self.log('\t\t\t', url)
                    current_articles.append({'title': title[0:title.find("|")-1], 'url':url,
                        'description':'', 'date':''})

            return current_articles


    # To GET SECTIONS
    def parse_index(self):
            feeds = []
            for title, url in [
                ('LETRAS',
                 'http://www.elcultural.es/pdf_sumario/cultural/Sumario_El_Cultural_en_PDF'),
                ('ARTE',
                 'http://www.elcultural.es/pdf_sumario/cultural/Sumario_El_Cultural_en_PDF'),
                ('CINE',
                 'http://www.elcultural.es/pdf_sumario/cultural/Sumario_El_Cultural_en_PDF'),
                ('CIENCIA',
                 'http://www.elcultural.es/pdf_sumario/cultural/Sumario_El_Cultural_en_PDF'),
##                ('OPINION',
##                 'http://www.elcultural.es/pdf_sumario/cultural/Sumario_El_Cultural_en_PDF'),
                ('ESCENARIOS',
                 'http://www.elcultural.es/pdf_sumario/cultural/Sumario_El_Cultural_en_PDF'),
             ]:
               articles = self.ec_parse_section(url,title)
               if articles:
                   feeds.append((title, articles))

            
            return feeds


Jeff.
jefferson_frantz is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ethnic / cultural fiction / biographical recommendations mgrunk Reading Recommendations 4 06-24-2009 08:57 PM
Seriously thoughtful US/Europe Cultural Divide -- Musings Xenophon Lounge 495 05-02-2009 04:08 PM
Page Error with Clive James - Cultural Amnesia kirky11 ePub 5 12-22-2008 04:25 PM
"Two Bits: The Cultural Significance of Free Software" - free e-book TadW Deals and Resources (No Self-Promotion or Affiliate Links) 0 06-11-2008 06:18 PM
Proposal: Digital Millennium Cultural Heritage Act nekokami News 12 01-22-2007 10:22 PM


All times are GMT -4. The time now is 07:12 PM.


MobileRead.com is a privately owned, operated and funded community.