Teraz jest 28 mar 2024 21:01:41




Utwórz nowy wątek Ten wątek jest zamknięty. Nie możesz w nim pisać ani edytować postów.  [ Posty: 242 ]  Przejdź na stronę Poprzednia strona  1 ... 13, 14, 15, 16, 17  Następna strona
Polskie treści w calibre - komentarze 
Autor Wiadomość
Użytkownik

Dołączył(a): 21 lut 2012 12:16:19
Posty: 11
eCzytnik: Kindle 3
Post Re: Polskie treści w calibre - komentarze
Jakiś czas temu pojawiły się recepty Runner's World i Men's Health. Poprawiłem je w taki sposób, że prawidłowo wyświetlane są sekcje i obsługiwane wielostronicowe artykuły. Załączam te recepturki.

Men's Health: Spoiler!
Kod:
__license__   = 'GPL v3'
__copyright__ = 'Marcin Urban 2011'
__modyfication__ = '2012, Krzysk(at)wp.pl'

import re
from calibre.web.feeds.recipes import BasicNewsRecipe

class recipeMagic(BasicNewsRecipe):
    title                       = "Men's Health PL"
    __author__            = 'Marcin Urban 2011'
    description             = u'Mens Health PL, lifestylowy magazyn dla mężczyzn <br>'
    cover_url               = u'http://www.menshealth.pl/images/logo.gif'
    masthead_url         = u'http://www.totalbody.net.au/product_images/uploaded_images/mens-health.jpg' #(KK)
    oldest_article         = 7
    max_articles_per_feed  = 100
    no_stylesheets       = True
    #delay                  = 1
    use_embedded_content   = False
    encoding               = 'utf8'
    publisher              = u'Motor Presse Polska'
    category               = u'news, PL,'
    language               = 'pl'
    publication_type     = 'magazine'
    extra_css              = ''' body {font-family: verdana, arial, helvetica, geneva, sans-serif ;}
                       h1{text-align: center;}
         h2{font-size: medium; font-weight: bold;}
      .art-data {font-size: x-small;}
                               .art-lead {font-weight: bold;}
                                        .img-head {font-size: x-small; color: #666666;}'''
    preprocess_regexps     = [(re.compile(r'<!--.*?-->', re.DOTALL), lambda m: '')]
    conversion_options = {
                             'tags'            : category
                            ,'language'        : language
                            ,'publisher'       : publisher
                   #         ,'linearize_tables': True
                         } #(KK)

    keep_only_tags    = [
                       dict(name='div', attrs={'class':'kol-670 big'})
                        ]

    remove_attributes = ['width','height']

    def parse_index(self): #(kk)
        soup = self.index_to_soup('http://www.menshealth.pl/rss.xml')
        feeds = []
        articles = {}
        sections = []
        section = ''

        for item in soup.findAll('item') :
                section = self.tag_to_string(item.category)
                if not articles.has_key(section) :
                    sections.append(section)
                    articles[section] = []
                article_url = self.tag_to_string(item.guid)
                article_title = self.tag_to_string(item.title)
                article_date = self.tag_to_string(item.pubDate)
                article_description = self.tag_to_string(item.description)
                articles[section].append( { 'title' : article_title,  'url' : article_url, 'date' : article_date, 'description' : article_description })

        for section in sections :
             feeds.append((section, articles[section]))
        return feeds

    def append_page(self, soup, appendtag):   #(kk)
        tags = soup.find('div', attrs={'class':'navibar'})
        for tag1 in tags.findAll('a') :
           if tag1.string == u'Fitness':
              section = 'fitness/'
           elif tag1.string == u'Dieta':
              section = 'dieta/'
           elif tag1.string == u'Zdrowie':
              section = 'zdrowie/'
           elif tag1.string == u'Seks/Związki':
              section = 'seks/'
           elif tag1.string == u'Pieniądze':
              section = 'praca/'
           elif tag1.string == u'Męskie sprawy':
              section = 'sprawy/'
           elif tag1.string == u'Styl':
              section = 'styl/'
           elif tag1.string == u'Hi-tech':
              section = 'hitech/'
           elif tag1.string == u'Wyzwania':
              section = 'wyzwania'

        apage = soup.find('div', attrs={'class':'stronice'})
        if apage is not None:
          for nexturl in apage.findAll('a'):
             if nexturl.string in ['2','3','4','5', '6', '7', '8', '9']:
                soup2 = self.index_to_soup('http://www.menshealth.pl/' + section + nexturl['href'])
                pagetext = soup2.findAll('div', attrs={'class':'kol-670 big'})
                for tag in pagetext:
                    pos = len(appendtag.contents)
                    appendtag.insert(pos, tag)

        while appendtag.find('div', attrs={'class': ['stronice', 'kol-160l', 'navibar', 'art-tagi', 'box-rek-336', 'Ocena-box', 'oh small']}) is not None:
            appendtag.find('div', attrs={'class': ['stronice', 'kol-160l', 'navibar', 'art-tagi', 'box-rek-336', 'Ocena-box', 'oh small']}).replaceWith('')

    def preprocess_html(self, soup): #(kk)
        self.append_page(soup, soup.body)
        return soup

    def get_cover_url(self): #(kk)
        soup = self.index_to_soup('http://www.menshealth.pl/archiwum.html')
        tag = soup.find(name='div', attrs={'class':'arch-l'})
        cover_url = 'http://www.menshealth.pl' + tag.img['src']
        return cover_url

    def populate_article_metadata(self, article, soup, first): #(kk)
        if first and hasattr(self, 'add_toc_thumbnail'):
            picdiv = soup.find('img')
            if picdiv is not None:
                self.add_toc_thumbnail(article,picdiv['src'])


Runner's World PL: Spoiler!
Kod:
__license__   = 'GPL v3'
__copyright__ = 'Marcin Urban 2011'
__modyfication__ = '2012, Krzysk(at)wp.pl'

import re
from calibre.web.feeds.recipes import BasicNewsRecipe

class recipeMagic(BasicNewsRecipe):
    title                  = "Runner's World PL"
    __author__             = 'Marcin Urban 2011'
    description            = 'Runners World PL, magazyn dla biegaczy  <br>'
    cover_url       = 'http://www.runners-world.pl/images/logo.png'
    masthead_url  = cover_url
    oldest_article         = 7
    max_articles_per_feed  = 100
    no_stylesheets         = True
    #delay                 = 1
    use_embedded_content   = False
    encoding               = 'utf8'
    publisher              = 'Motor Presse Polska'
    category               = 'news, PL, runners'
    language               = 'pl'
    publication_type       = 'magazine'
    extra_css              = ''' body {font-family: verdana, arial, helvetica, geneva, sans-serif ;}
                       h1{text-align: center;}
                          h2{font-size: medium; font-weight: bold;}
                          .authordate {font-size: small; color: #696969;}
                          p.lead {font-weight: bold; text-align: center;}
                          .fot{font-size: x-small; color: #666666;} '''
    preprocess_regexps     = [(re.compile(r'<!--.*?-->', re.DOTALL), lambda m: '')]
    conversion_options = {
                             'comments'        : description
                            ,'tags'            : category
                            ,'language'        : language
                            ,'publisher'       : publisher
                   #         ,'linearize_tables': True
                         } #(KK)

    keep_only_tags    = [
                       dict(name='div', attrs={'class':'kol-670 big'})
                        ]

    remove_attributes = ['width','height']

    def parse_index(self): #(kk)
        soup = self.index_to_soup('http://www.runners-world.pl/rss.xml')
        feeds = []
        articles = {}
        sections = []
        section = ''

        for item in soup.findAll('item') :
                section = self.tag_to_string(item.category)
                if not articles.has_key(section) :
                    sections.append(section)
                    articles[section] = []
                article_url = self.tag_to_string(item.guid)
                article_title = self.tag_to_string(item.title)
                article_date = self.tag_to_string(item.pubDate)
                article_description = self.tag_to_string(item.description)
                articles[section].append( { 'title' : article_title,  'url' : article_url, 'date' : article_date, 'description' : article_description })

        for section in sections :
             feeds.append((section, articles[section]))
        return feeds

    def append_page(self, soup, appendtag):   
        tags = soup.find('div', attrs={'class':'navibar'})
        for tag1 in tags.findAll('a') :
           if tag1.string == u'Trening':
              section = 'trening/'
           elif tag1.string == u'Dieta':
              section = 'dieta/'
           elif tag1.string == u'Zdrowie':
              section = 'zdrowie/'
           elif tag1.string == u'Sprzęt':
              section = 'sprzet/'
           elif tag1.string == u'Ludzie':
              section = 'ludzie/'
           elif tag1.string == u'Biegi':
              section = 'biegi/'

        apage = soup.find('div', attrs={'class':'stronice'})
        if apage is not None:
          for nexturl in apage.findAll('a'):
             if nexturl.string in ['2','3','4','5', '6', '7', '8', '9']:
                soup2 = self.index_to_soup('http://www.runners-world.pl/' + section + nexturl['href'])
                pagetext = soup2.findAll('div', attrs={'class':'kol-670 big'})
                for tag in pagetext:
                    pos = len(appendtag.contents)
                    appendtag.insert(pos, tag)

        while appendtag.find('div', attrs={'class': ['stronice', 'kol-160l', 'navibar', 'art-tagi', 'box-rek-336', 'Ocena-box', 'oh small']}) is not None:
            appendtag.find('div', attrs={'class': ['stronice', 'kol-160l', 'navibar', 'art-tagi', 'box-rek-336', 'Ocena-box', 'oh small']}).replaceWith('')

    def preprocess_html(self, soup):
        self.append_page(soup, soup.body)
        return soup

    def get_cover_url(self):
        soup = self.index_to_soup('http://www.runners-world.pl/archiwum.html')
        tag = soup.find(name='div', attrs={'class':'arch-l'})
        cover_url = 'http://www.runners-world.pl' + tag.img['src']
        return cover_url

    def populate_article_metadata(self, article, soup, first): #(kk)
        if first and hasattr(self, 'add_toc_thumbnail'):
            picdiv = soup.find('img')
            if picdiv is not None:
                self.add_toc_thumbnail(article,picdiv['src'])


I jeszcze raz, poprawnie sformatowane ;) , GamesFanatic: Spoiler!
Kod:
__license__    = 'GPL v3'
__copyright__ = '2012, Krzysk(at)wp.pl'
'''
www.gamesfanatic.pl
'''
class GamesFanaticRecipe(BasicNewsRecipe):
  title             = u'GamesFanatic'
  description   = u'Gry planszowe i karciane, recenzje, zapowiedzi, felietony, wieści i nowości ze świata. <br>'
  __author__  = u'Krzysk(at)wp.pl'
  __version__ = '1.0'

  oldest_article = 15
  max_articles_per_feed = 100
  publisher    = u'gamesfanatic.pl'
  category    = u'Gry, Gry planszowe, Planszówki, News'
  publication_type = 'blog'
  cover_url    = u'http://www.gamesfanatic.pl/wp-content/uploads/2011/12/gflogo.png'
  language    = 'pl'

  auto_cleanup        = True

  conversion_options = {
                              'tags'                : category
                            , 'language'         : language
                            , 'publisher'         : publisher
                         }

  feeds  = [(u'Artykuły', u'http://www.gamesfanatic.pl/feed/')]

  def populate_article_metadata(self, article, soup, first):
        if first and hasattr(self, 'add_toc_thumbnail'):
            picdiv = soup.find('img')
            if picdiv is not None:
                self.add_toc_thumbnail(article,picdiv['src'])


21 lut 2012 14:53:11
Zobacz profil
Użytkownik

Dołączył(a): 21 lut 2012 12:16:19
Posty: 11
eCzytnik: Kindle 3
Post Re: Polskie treści w calibre - komentarze
Kolejne recepturki

Mobile Internet: Spoiler!
Kod:
__license__    = 'GPL v3'
__copyright__ = '2012, Krzysk(at)wp.pl'
'''
http://www.mobile-internet.pl
'''
from calibre.web.feeds.news import BasicNewsRecipe
import re
class Mobile_Internet(BasicNewsRecipe):
    title            = u'Mobile Internet'
    description  = u'<b>Mobile Internet</b> - Portal z nowoczesnymi technologiami mobilnymi. Komórki, PDA, notebooki, palmtopy, baza telefonów, dzwonki, tapety, gry. <br>'
    __author__ = u'Krzysk(at)wp.pl'
    __version__='1.0'

    oldest_article = 15
    max_articles_per_feed = 100
    publisher    = u'www.mobile-internet.pl Wydawnictwo Westa-Druk '
    category    = u'IT, News'
    masthead_url = 'http://www.mobile-internet.pl/images/logo.gif'
    publication_type = 'magazine'
    language    = 'pl'

    remove_javascript     = True
    remove_empty_feeds = True
   
    preprocess_regexps = [
        (re.compile(r'\<td\>\<tr\>\<\/table\>'), lambda match: ''),
        (re.compile(r'\<table .*?\>'), lambda match: ''),
        (re.compile(r'\<tr>'), lambda match: ''),
        (re.compile(r'\<td .*?\>'), lambda match: '')]
   
    remove_tags_before = dict(dict(name = 'h2', attrs = {'class' : 'news_head_h'}))     
    remove_tags_after = dict(dict(name = 'div', attrs = {'class' : 'news_source'}))

    remove_tags = [
        dict(name='div', attrs={'class':'addthis_toolbox addthis_default_style'}),
#      dict(name='a', attrs={'class':'highslide'}),
        dict(name='p', attrs={'style': 'font-weight: bold;'})]

    extra_css ='''
            h1{font-size: x-small;  color: #666666;}
            h2.news_head_h{font-size: x-large; color: #222222;}
            body{font-size: small;}
            div.news_autor{font-size: x-small;}
            div.news_source{font-size: x-small;}
            '''

    conversion_options = {
                              'tags'                : category
                            , 'language'         : language
                            , 'publisher'         : publisher
                            , 'linearize_tables': True
                         }

    feeds  = [(u'Telefony',    u'http://www.mobile-internet.pl/RSS,1'),
                   (u'Odtwarzacze', u'http://www.mobile-internet.pl/RSS,2'),
                   (u'Notebooki', u'http://www.mobile-internet.pl/RSS,3'),
                   (u'PDA i GPS', u'http://www.mobile-internet.pl/RSS,4'),
                   (u'Dyski',    u'http://www.mobile-internet.pl/RSS,5'),
                   (u'Akcesoria',    u'http://www.mobile-internet.pl/RSS,6'),
                   (u'Wydarzenia', u'http://www.mobile-internet.pl/RSS,7'),
                   (u'Usługi',    u'http://www.mobile-internet.pl/RSS,8'),
                   (u'VoIP',    u'http://www.mobile-internet.pl/RSS,9'),
                   (u'Aparaty cyfrowe', u'http://www.mobile-internet.pl/RSS,10'),
                   (u'Projektory', u'http://www.mobile-internet.pl/RSS,11'),
                   (u'Felietony',    u'http://www.mobile-internet.pl/RSS,12'),
                   (u'Komentarze', u'http://www.mobile-internet.pl/RSS,13'),
                   (u'O swoich telefonach', u'http://www.mobile-internet.pl/RSS,14'),
                   (u'Tablety',    u'http://www.mobile-internet.pl/RSS,15'),
                   (u'Netbooki',    u'http://www.mobile-internet.pl/RSS,16')]

    def get_cover_url(self):   
        soup = self.index_to_soup('http://www.mobile-internet.pl')
        cover_item = soup.find('img', attrs={'alt' : 'Mobile Internet - najnowsze wydanie'})
        if cover_item:
           cover_url = 'http://www.mobile-internet.pl' + cover_item['src']
        else:
           cover_url = masthead_url
        return cover_url

    def populate_article_metadata(self, article, soup, first):
        if first and hasattr(self, 'add_toc_thumbnail'):
            picdiv = soup.find('img')
            if picdiv is not None:
                self.add_toc_thumbnail(article,picdiv['src'])


Telemagazyn: Spoiler!
Kod:
__license__    = 'GPL v3'
__copyright__ = '2012, Krzysk(at)wp.pl'
'''
www.telemagazyn.pl
'''
class TelemagazynRecipe(BasicNewsRecipe):
    title             = u'Telemagazyn'
    description   = u'Aktualny program telewizyjny polskich i zagranicznych stacji. <br>'
    __author__  = u'Krzysk(at)wp.pl'
    __version__ = '1.0'

    oldest_article = 2
    max_articles_per_feed = 100
    category    = u'program tv, program telewizyjny, recenzje filmów, plotki'
    publisher    = u'Polskapresse Sp. z o.o.'
    cover_url    = 'http://s.telemagazyn.pl/g/logo.gif'
    publication_type = 'newspaper'
    language   =  'pl'

    auto_cleanup             = True
    no_stylesheets           = True
    remove_javascript      = True
    remove_empty_feeds = True
   # reverse_article_order = True

    conversion_options = {
                             'tags'                : category
                            ,'language'         : language
                            ,'publisher'         : publisher
                       #   ,'base_font_size' : 16
                               }
    feeds          = [
                        #   (u'Program TV', u'http://www.telemagazyn.pl/program-tv/rss-glowna/'),
                           (u'Hity dnia', u'http://www.telemagazyn.pl/rss/hit,krss.xml'),
                        #   (u'Seriale', u'http://www.telemagazyn.pl/rss/seriale,krss.xml'),
                           (u'Polecamy', u'http://www.telemagazyn.pl/rss/polecamy,krss.xml'),
                           (u'Video', u'http://www.telemagazyn.pl/rss/video,krss.xml'),
                           (u'Wieczorem', u'http://www.telemagazyn.pl/rss/wieczor,krss.xml'),
                         #  (u'Plotki', u'http://www.telemagazyn.pl/rss/plotki,krss.xml'),
                           (u'TVN Turbo', u'http://www.telemagazyn.pl/rss/46,stacja,st,krss.xml'),
                           ]

Tej recepturki używam do codziennego przeglądu co ciekawego jest w telewizji (SAT). Można samodzielnie skonfigurować dla których kanałów mają być pobrane pełne plany (przykład zawiera definicje dla TVN Turbo).

Auto-News.pl: Spoiler!
Kod:
__license__    = 'GPL v3'
__copyright__ = '2012, Krzysk(at)wp.pl'
'''
www.auto-news.pl
'''
class AutoNewsRecipe(BasicNewsRecipe):
    title             = u'Auto-News.pl'
    description   = u'Auto-News.pl - portal motoryzacyjny to najświeższe wiadomości motoryzacyjne. Newsy, Testy, Auta używane, Raporty, Porady, Motosport <br>'
    __author__  = u'Krzysk(at)wp.pl'
    __version__ = '1.0'   

    oldest_article = 10
    max_articles_per_feed = 100
    publisher    = u'www.auto-news.pl'
    category    = u'Motoryzacja, News'
    cover_url     = 'http://www.auto-news.pl/images/logo_stare.gif'
    publication_type = 'magazine'
    language    = 'pl'

    no_stylesheets    = True
    remove_javascript    = True
    remove_empty_feeds    = True
    reverse_article_order   = True

    conversion_options = {
                              'tags'                : category
                            , 'language'         : language
                            , 'publisher'         : publisher
                         }

    keep_only_tags= [dict(attrs={'class':'srodek_body'})]

    feeds = [(u'News',    u'http://www.auto-news.pl/rss/rss_news.php'),
                 (u'Motorsport',    u'http://www.auto-news.pl/rss/rss_moto_sport.php'),
                 (u'Wydarzenia', u'http://www.auto-news.pl/rss/rss_wydarzenia.php'),
                 (u'Prezentacje', u'http://www.auto-news.pl/rss/rss_prezentacje.php'),
                 (u'Testy',    u'http://www.auto-news.pl/rss/rss_testy.php'),
                 (u'Raporty',    u'http://www.auto-news.pl/rss/rss_raporty.php'),
                 (u'Porównania', u'http://www.auto-news.pl/rss/rss_porownania.php'),
                 (u'Bezpieczeństwo', u'http://www.auto-news.pl/rss/rss_bezpieczenstwo.php'),
                 (u'Używane',    u'http://www.auto-news.pl/rss/rss_uzywane.php'),
                 (u'Porady',    u'http://www.auto-news.pl/rss/rss_porady.php'),
                 (u'Concept Cars', u'http://www.auto-news.pl/rss/rss_concept_cars.php'),
                 (u'Technika',    u'http://www.auto-news.pl/rss/rss_technika.php'),
                 (u'Auto Fanatyk', u'http://www.auto-news.pl/rss/rss_auto_fanatyk.php'),
                 (u'Kobiecym Okiem', u'http://www.auto-news.pl/rss/rss_kobiecym_okiem.php'),
                 (u'Gorące tematy', u'http://www.auto-news.pl/rss/rss_gorace_tematy.php'),
                 (u'Czy wiesz że...', u'http://www.auto-news.pl/rss/rss_czy_wiesz_ze.php'),
                 (u'Ciekawostki', u'http://www.auto-news.pl/rss/rss_ciekawostki.php'),
                 (u'Turystyka',    u'http://www.auto-news.pl/rss/rss_turystyka.php')]

    def populate_article_metadata(self, article, soup, first):
        if first and hasattr(self, 'add_toc_thumbnail'):
            picdiv = soup.find('img')
            if picdiv is not None:
                self.add_toc_thumbnail(article,picdiv['src'])


21 lut 2012 15:34:09
Zobacz profil
Użytkownik

Dołączył(a): 21 lut 2012 12:16:19
Posty: 11
eCzytnik: Kindle 3
Post Re: Polskie treści w calibre - komentarze
Trochę recept motoryzacyjnych

Autokult - blog motoryzacyjny: Spoiler!
Kod:
__license__    = 'GPL v3'
__copyright__ = '2012, Krzysk(at)wp.pl'
'''
Autokult.pl
'''
class Autokult_pl(BasicNewsRecipe):
    title          = u'Autokult'
    description        = u'Autokult.pl - blog motoryzacyjny. <br />'
    __author__       = u'Krzysk(at)wp.pl'
    __version__      = '1.0'

    oldest_article = 7
    max_articles_per_feed = 30

    publisher          = u'Blomedia Sp. z o.o. <br />al. Stanów Zjednoczonych 26a <br />03-964 Warszawa'
    category           = u'Motoryzacja, news'
    publication_type= 'blog'
    cover_url          = u'http://autokult.pl/images/2009/03/autokult.jpg'
    language           = 'pl'
      
    auto_cleanup            = True
    no_stylesheets          = True
    remove_javascript     = True

    conversion_options = {
                             'tags'                : category
                            ,'language'         : language
                            ,'publisher'         : publisher
                          }


    feeds = [(u'Auto', u'http://autokult.pl/feed/rss2')]

    def populate_article_metadata(self, article, soup, first):
        if first and hasattr(self, 'add_toc_thumbnail'):
            picdiv = soup.find('img')
            if picdiv is not None:
                self.add_toc_thumbnail(article,picdiv['src'])   


Auto Motor i Sport: Spoiler!
Kod:
#!/usr/bin/env  python
__license__    = 'GPL v3'
__copyright__ = '2012, Krzysk(at)wp.pl'
'''
www.auto-motor-i-sport.pl
'''
from calibre.web.feeds.recipes import BasicNewsRecipe
class recipeAMiS(BasicNewsRecipe):
    title                  = u'Auto Motor i Sport'
    description        = u'auto motor i sport - testy, raporty, nowości, samochody, ceny, zdjęcia, filmy, opinie użytkowników <br>'
    __author__       = u'Krzysk(at)wp.pl'
    __version__      = '1.0'

    oldest_article         = 15
    max_articles_per_feed  = 100
    publisher          = u'Motor Presse Polska'
    category           = u'testy,  News, Motoryzacja'
    publication_type= 'magazine'
    cover_url          = 'http://www.auto-motor-i-sport.pl/images/logo.gif'
    language          = 'pl'
    timefmt            = ' [%d.%m.%Y %H:%M]'

    no_stylesheets          = True
    remove_javascript     = True
    remove_empty_feeds = True

    conversion_options = {
                             'tags'                : category
                            ,'language'         : language
                            ,'publisher'         : publisher
                          }

    keep_only_tags  = [ dict(name='div', attrs={'id':'content'}) ]

    feeds  = [ (u'Wiadomości', u'http://www.auto-motor-i-sport.pl/wiadomosci/wiadomosci.rss'),
                   (u'Artykuły',       u'http://www.auto-motor-i-sport.pl/magazyn/article.rss'),
                   (u'Felietony',       u'http://www.auto-motor-i-sport.pl/magazyn/blog.rss'),
                   (u'Technologie',  u'http://www.auto-motor-i-sport.pl/magazyn/technologie.rss'),
              #     (u'Multimedia', u'http://www.auto-motor-i-sport.pl/magazyn/multimedia.rss'),
                   (u'Raporty',       u'http://www.auto-motor-i-sport.pl/testy/raport.rss'),
                   (u'Testy',       u'http://www.auto-motor-i-sport.pl/testy/test.rss'),
                   (u'Porównania',  u'http://www.auto-motor-i-sport.pl/testy/porownanie.rss'),
                   (u'Testy porównawcze', u'http://www.auto-motor-i-sport.pl/testy/test-porownawczy.rss'),
                   (u'Testy długodystansowe', u'http://www.auto-motor-i-sport.pl/testy/test-dlugodystansowy.rss'), ]

    def append_page(self, soup, appendtag) :   
        pagination = soup.find(name= 'span', attrs={'class':'pageNums'})
        if pagination is not None:
           for nexturl in pagination.findAll(name = 'a') :
              if '1' not in nexturl.string :
                soup2 = self.index_to_soup('http://www.auto-motor-i-sport.pl/testy/' + nexturl['href'])
                pagetext = soup2.findAll(name='div', attrs={'id':'artBody'})
                for tag in pagetext :
                    pos = len(appendtag.contents)
                    appendtag.insert(pos, tag)

        while appendtag.find(name= 'div', attrs={'class':['pagination', 'artSideL']}) is not None :
            appendtag.find(name= 'div', attrs={'class':['pagination', 'artSideL']}).replaceWith('')
        while appendtag.find(name= 'div', attrs={'id':['artFooter','artRate','relatedNews','artComments']}) is not None :
            appendtag.find(name= 'div', attrs={'id':['artFooter','artRate','relatedNews','artComments']}).replaceWith('')
        while appendtag.find(attrs={'class':'optBox'}) is not None :
            appendtag.find(attrs={'class':'optBox'}).replaceWith('')

    def preprocess_html(self, soup) :
         self.append_page(soup, soup.body)
         return soup

    def populate_article_metadata(self, article, soup, first):
        if first and hasattr(self, 'add_toc_thumbnail'):
            picdiv = soup.find('img')
            if picdiv is not None:
                self.add_toc_thumbnail(article,picdiv['src'])

Recepta ta wymaga dopracowanie, gdyż nie pomija starych artykułów

Coś dla fanów F1: Wyprzedź mnie!: Spoiler!
Kod:
__license__    = 'GPL v3'
__copyright__ = '2012, Krzysk(at)wp.pl'
'''
www.f1wm.pl
'''
from calibre.web.feeds.news import BasicNewsRecipe

class WyprzedzMnieRecipe(BasicNewsRecipe):
    title             = u'Wyprzedź Mnie!'
    description   = u'Formuła 1 - aktualności, relacje z wyścigów, statystyki sezonowe, informacje o zespołach, bolidach, kierowcach i torach, artykuły, forum, galeria; dedykowane działy: Robert Kubica, Inne serie wyścigowe <br>'
    __author__  = u'Krzysk(at)wp.pl'
    __version__ = '1.0'

    oldest_article = 7
    max_articles_per_feed = 100
    category    = u'Formula 1, Kubica, News, Motoryzacja'
    publisher    = u'F1WM.pl – Wyprzedź Mnie!'
    cover_url    = 'http://www.f1wm.pl/rss/wm_logo_feed.png'
    publication_type = 'blog'
    language    = 'pl'

    no_stylesheets          = True
    remove_javascript     = True
    remove_empty_feeds = True

    keep_only_tags =[]
    keep_only_tags.append(dict(name = 'h2'))
    keep_only_tags.append(dict(attrs = {'class' : 'tekst'}))
#    keep_only_tags.append(dict(name = 'div', attrs = {'id' : 'trescnewsa'}))
    keep_only_tags.append(dict(attrs = {'class' : 'tekst2p'}))

    remove_tags = []
    remove_tags.append(dict(name= 'table', attrs ={'width' : '100%'}))

    extra_css = '''
                .tekst2p {font-size: x-small}
                .trhl {font-size: x-small}
                table {font-size: x-small}
                      '''
    conversion_options = {
                              'tags'                : category
                            , 'language'         : language
                            , 'publisher'         : publisher
                         }

    def parse_pages(self, soup, section, articles) :
        if not articles.has_key(section) :
             articles[section] = []
        for a in soup.findAll(name = 'a', attrs = {'class' : ['newstytlink','newstytlinkb']}) :
             article_url = a['href'].replace('../php/', '').replace('..//php/', '').replace('../', 'http://f1wm.pl/')
             if 'http' not in article_url :
                article_url = 'http://f1wm.pl/php/' + article_url
             self.log(article_url)
             article_page = self.index_to_soup(article_url)
             if article_page.findAll(attrs={'class' : 'tekst'}) == [] :
                descript = ''
             else :
                descript = self.tag_to_string( article_page.findAll(attrs={'class' : 'tekst'})[0] )
             articles[section].append( { 'title' : self.tag_to_string(a) , 'url' : article_url, 'date' : '', 'description' : descript })
        return articles

    def parse_clasification(self, soup, section, articles) :
        if not articles.has_key(section) :
             articles[section] = []
        articles[section].append( { 'title' : 'Klasyfikacja F1' ,
   'url' : 'http://www.f1wm.pl/php/sez_gen.php?rok=2011&dzial=3',
   'date' : '',
   'description' : '' })
        return articles

    def parse_index(self) :
        feeds = []
        articles = {} [code][/code]
        articles = self.parse_pages(self.index_to_soup('http://f1wm.pl/php/wiad_gen.php?typ=1'), 'Formuła 1', articles)
        articles = self.parse_pages(self.index_to_soup('http://f1wm.pl/php/wiad_gen.php?typ=5'), 'Inne serie', articles)
        #articles = self.parse_pages(self.index_to_soup('http://f1wm.pl/php/wiad_gen.php?typ=3'), 'Artykuły', articles)
  #      articles = self.parse_clasification(self.index_to_soup('http://www.f1wm.pl/php/sez_gen.php?rok=2011&dzial=3'), 'Klasyfikacja', articles)

        for section in articles :
             feeds.append((section, articles[section]))
        return feeds


Ponieważ często przeglądam wiele serwisów dotyczących F1, na własne potrzeby stworzyłem recepte, która zbiera newsy z wielu portali: Sokolimokiem.tv, formula1.pl, Motorsport24.pl, F1 Ultra, F1Talks.pl, autoklub.pl, Formula1.com.
Może komuś też się przyda? Aktualności F1: Spoiler!
Kod:
#!/usr/bin/env  python
__license__    = 'GPL v3'
__copyright__ = '2012, Krzysk(at)wp.pl'
'''
Aktualności z portali: Sokolimokiem.tv, formula1.pl, Motorsport24.pl, F1 Ultra, F1Talks.pl, autoklub.pl, Formula1.com
'''
class AktualnosciF1Recipe(BasicNewsRecipe):
    title              = u'Aktualności F1'
    description    = u'Wieści z padoku F1: SokolimOkiem, Dziel Pasję, Motorsport24, F1 Ultra, F1 Talks, Lotus Renault GP, Autoklub.pl, Formula1.com <br>'
    __author__   = u'Krzysk(at)wp.pl'
    __version__  = '1.1'   

    oldest_article = 7  # w sezonie wyścigowym ustawić 4 dni (sciagac 2 razy w tygodniu: pn, pt)
    max_articles_per_feed = 100
    category    = u'Formula 1, Motoryzacja, News'
    publisher    = u'Sokolimokiem.tv, formula1.pl, Motorsport24.pl, F1 Ultra, F1Talks.pl, autoklub.pl, Formula1.com'
    cover_url    = u'http://apuestasformula1.com.es/wp-content/uploads/2008/09/formula-one-logo-thumb.jpg'
    masthead_url = u'http://www.itv.com/formula1/3e57e806-03f7-405c-9110-a45e17ec631d/PreviewFile.jpg.ashx?'
    publication_type = 'magazine'
    language    = 'pl'

    auto_cleanup        = True
    no_stylesheets      = True
    remove_javascript = True
    remove_empty_feeds = True
    center_navbar      = False

    remove_tags = [
        dict(name='div', attrs={'id':'addTo'}),
        dict(name='div', attrs={'id':'events'}),
        dict(name='div', attrs={'id':'header'}),
        dict(name='div', attrs={'class':'pagination'}),
        dict(name='div', attrs={'id':'footer'}),
        dict(name='div', attrs={'id':'left_sidebar'}),
        dict(name='div', attrs={'id':'top_billboard'}),
        dict(name='div', attrs={'id':'right_sidebar'}),
        dict(name='p', attrs={'style':'float:right;'}),
        dict(name='a', attrs={'class':'twitter-share-button'}),
            dict(name='div', attrs={'align':'center'}),
        dict(name='div', attrs={'class':'news_view_similar'}),
        dict(attrs={'class':'commonTools float_right'}),
        dict(attrs={'class':'toppanel'}),
        dict(attrs={'class':'buttonheading'}),
        dict(name='img', attrs={'src':'http://www.Formula1.pl/graf2/2_comment.gif'}), # usuwane a uwagi na thumbnails w TOC
        ]

    extra_css = '''h1 { font-size: x-large; }
                        h2 { font-size: large; }
                        span.date { font-size: small; }
                        body { font-size: small; }
                     '''
    conversion_options = {
                     'tags'                : category
   ,'language'         : language
   ,'publisher'         : publisher
   ,'linearize_tables': True }

    feeds = [(u'SokolimOkiem', u'http://sokolimokiem.tv/?feed=rss2'),
          (u'Dziel Pasję',u'http://www.formula1.pl/rss.php'),
          (u'Motorsport24', u'http://www.motorsport24.pl/RSS.221.100.html'),
          (u'F1 Ultra',u'http://www.f1ultra.pl/index.php?format=feed&type=rss'),
          (u'F1 Talks', u'http://www.f1talks.pl/?feed=rss2'),
          (u'Autoklub.pl', u'http://www.autoklub.pl/rss2.php'),
          (u'Formula1.com', u'http://www.formula1.com/rss/news/latest.rss')]

    def populate_article_metadata(self, article, soup, first):
        if first and hasattr(self, 'add_toc_thumbnail'):
            picdiv = soup.find('img')
            if picdiv is not None :
                self.add_toc_thumbnail(article,picdiv['src'])


Pracuję teraz nad tygodnikiem Auto Świat. Jak uporam się z problemem (calibre nie radzi sobie z błędnymi tagami w kodzie html na portalu), zamieszczę efekt.


21 lut 2012 16:33:35
Zobacz profil
Admin

Dołączył(a): 13 cze 2008 14:47:02
Posty: 2835
Lokalizacja: Gdańsk
eCzytnik: kindle
Post Re: Polskie treści w calibre - komentarze
Ja bym prosił o edytowanie postów, a nie pisanie kolejnych seriami.

Cytuj:
Pracuję teraz nad tygodnikiem Auto Świat. Jak uporam się z problemem (calibre nie radzi sobie z błędnymi tagami w kodzie html na portalu), zamieszczę efekt.

Może preprocess_regexps pomoże?

_________________
Zgred - Rafał Ziemkiewicz napisał(a):
Dziś trzeba pisać o mieczach, czarach, toporach i wojowniczkach w blaszanych bikini, wszystko inne to już jest nisza w niszy. Albo o nastoletnich wampirach.
Porównywarka cen ebooków


21 lut 2012 16:39:11
Zobacz profil WWW
Użytkownik

Dołączył(a): 15 sty 2010 0:26:35
Posty: 19
Post Re: Polskie treści w calibre - komentarze
Czy ktoś biegły w receptach miałby chwilę popatrzeć na receptę do Esensji?
W aktualnym numerze http://www.esensja.pl/magazyn/2012/01/iso/01.html linki są robione inaczej niż wcześniej i niestety stara recepta przestała działać :(
A my z Pythonem co prawda próbujemy się polubić, ale jakoś na razie nadal nam nie wychodzi :::?

_________________
Darek-


25 lut 2012 11:50:04
Zobacz profil
Użytkownik

Dołączył(a): 21 lut 2012 12:16:19
Posty: 11
eCzytnik: Kindle 3
Post Re: Polskie treści w calibre - komentarze
dsznajder napisał(a):
Czy ktoś biegły w receptach miałby chwilę popatrzeć na receptę do Esensji?
W aktualnym numerze <!-- m --><a class="postlink" href="http://www.esensja.pl/magazyn/2012/01/iso/01.html">http://www.esensja.pl/magazyn/2012/01/iso/01.html</a><!-- m --> linki są robione inaczej niż wcześniej i niestety stara recepta przestała działać :(
A my z Pythonem co prawda próbujemy się polubić, ale jakoś na razie nadal nam nie wychodzi :::?
Link do artykułów podawane są w innej postaci. Zastosowałem więc protezą: wstawiłem self.HREF = '' tak aby cała recepta działała poprawnie. Całość wygląda tak: Spoiler!
Kod:
#!/usr/bin/env  python

__license__   = 'GPL v3'
__copyright__ = '2010, matek09, matek09@gmail.com'

from calibre.web.feeds.news import BasicNewsRecipe
import re

class Esensja(BasicNewsRecipe):

   title = u'Esensja'
   __author__ = 'matek09'
   description = 'Monthly magazine'
   encoding = 'utf-8'
   no_stylesheets = True
   language = 'pl'
   remove_javascript = True
   HREF = '0'

   #keep_only_tags =[]
   #keep_only_tags.append(dict(name = 'div', attrs = {'class' : 'article'})
   remove_tags_before = dict(dict(name = 'div', attrs = {'class' : 't-title'}))
   remove_tags_after = dict(dict(name = 'img', attrs = {'src' : '../../../2000/01/img/tab_bot.gif'}))

   remove_tags =[]
   remove_tags.append(dict(name = 'img', attrs = {'src' : '../../../2000/01/img/tab_top.gif'}))
   remove_tags.append(dict(name = 'img', attrs = {'src' : '../../../2000/01/img/tab_bot.gif'}))
   remove_tags.append(dict(name = 'div', attrs = {'class' : 't-title2 nextpage'}))

   extra_css = '''
               .t-title {font-size: x-large; font-weight: bold; text-align: left}
               .t-author {font-size: x-small; text-align: left}
               .t-title2 {font-size: x-small; font-style: italic; text-align: left}
               .text {font-size: small; text-align: left}
               .annot-ref {font-style: italic; text-align: left}
            '''

   preprocess_regexps = [(re.compile(r'alt="[^"]*"'),
                  lambda match: '')]

   def parse_index(self):
      soup = self.index_to_soup('http://www.esensja.pl/magazyn/')
      a = soup.find('a', attrs={'href' : re.compile('.*/index.html')})
      year = a['href'].split('/')[0]
      month = a['href'].split('/')[1]
      self.HREF = 'http://www.esensja.pl/magazyn/' + year + '/' + month + '/iso/'
      soup = self.index_to_soup(self.HREF + '01.html')
      self.HREF = '' #KK
      self.cover_url = 'http://www.esensja.pl/magazyn/' + year + '/' + month + '/img/ilustr/cover_b.jpg'
      feeds = []
      intro = soup.find('div', attrs={'class' : 'n-title'})
      introduction = {'title' : self.tag_to_string(intro.a),
                  'url' : self.HREF + intro.a['href'],
                  'date' : '',
                  'description' : ''}
      chapter = 'Wprowadzenie'
      subchapter = ''
      articles = []
      articles.append(introduction)
      for tag in intro.findAllNext(attrs={'class': ['chapter', 'subchapter', 'n-title']}):
         if tag.name in 'td':
            if len(articles) > 0:
               section = chapter
               if len(subchapter) > 0:
                  section += ' - ' + subchapter
               feeds.append((section, articles))
               articles = []
            if tag['class'] == 'chapter':
               chapter = self.tag_to_string(tag).capitalize()
               subchapter = ''
            else:
               subchapter = self.tag_to_string(tag)
               subchapter = self.tag_to_string(tag)
            continue
         articles.append({'title' : self.tag_to_string(tag.a), 'url' : self.HREF + tag.a['href'], 'date' : '', 'description' : ''})

         a = self.index_to_soup(self.HREF + tag.a['href'])
         i = 1
         while True:
            div = a.find('div', attrs={'class' : 't-title2 nextpage'})
            if div is not None:
               a = self.index_to_soup(self.HREF + div.a['href'])
               articles.append({'title' : self.tag_to_string(tag.a) + ' c. d. ' + str(i), 'url' : self.HREF + div.a['href'], 'date' : '', 'description' : ''})
               i = i + 1
            else:
               break

      return feeds


25 lut 2012 12:52:16
Zobacz profil
Użytkownik

Dołączył(a): 21 lut 2012 12:16:19
Posty: 11
eCzytnik: Kindle 3
Post Re: Polskie treści w calibre - komentarze
Cytuj:
Może preprocess_regexps pomoże?


Niestety nie mogę sobie poradzić ze stroną Auto Swiat. preprocess_regexps także nie działa, gdyż problem jest z parsowaiem strony zawierającej spis treści. Calibre źle odczytuje tagi <script> i nie widzi zakończenia tego tagu a tym samym nie da się wyciągnąć innych tagów/pozycji z tej strony (Dokładnie to na stronie http://www.auto-swiat.pl/wydania/w - calibre nie rozpoznaje zakończenie czwartego tagu <script>, tag ten ciągnie się do końca html-a ). Czy ma ktoś sugestie co jest nie tak?


25 lut 2012 18:04:02
Zobacz profil
Użytkownik

Dołączył(a): 15 sty 2010 0:26:35
Posty: 19
Post Re: Polskie treści w calibre - komentarze
Krzysk napisał(a):
Link do artykułów podawane są w innej postaci. Zastosowałem więc protezą: wstawiłem self.HREF = '' tak aby cała recepta działała poprawnie.

Dzięki. Teraz ściąga, ale wygląda na to, że pozmieniali nie tylko linki - wielostronicowe artykuły mają tylko pierwszą stronę.
Zastanawiam się też, czy nie ściągnął więcej niż jest w magazynie (bo treści wyszło duuużo), ale może "grubość" to tylko efekt wrzucenia komentarzy z portalu, bo dat jakichś mocno wstecznych w artykułach nie widać.

Próbowałem wcześniej zrobić tak, że ściągnąć ZIPa z magazynem (tam linki ze spisu treści są po staremu i nie ma komentarzy) i zmienić w recepcie domenę, ale ta ścieżka też nie bardzo mi wyszła - chyba pozmieniali też cały układ strony i nawigację. :\

_________________
Darek-


25 lut 2012 18:35:55
Zobacz profil
Użytkownik

Dołączył(a): 06 mar 2012 15:06:06
Posty: 21
eCzytnik: Onyx 60, Sony T1, Kobo Glo
Post Re: Moje recepty Calibre (GW, DI + inne)
Cześć,
Pobrałem sobie z https://github.com/t3d/kalibrator receptę na Rzeczpospolitą, jednak nie pobiera mi ona tekstu artykułów. Czy ktoś bardziej obeznany w temacie mógłby zajrzeć w kod i sprawdzić czy wszystko jest ok? Nie przeczę, że to być może jakiś problem u mnie, chociaż reszta recept działa ok.
Dzięki i pozdrawiam!


10 mar 2012 13:43:00
Zobacz profil
Użytkownik

Dołączył(a): 29 mar 2012 21:49:35
Posty: 1
eCzytnik: Kindle Touch
Post Re: Polskie treści w calibre - komentarze
Witam
Ktoś potrafi stworzyć recepturę dla strony http://militarium.net/ ?
Ja próbowałem, ale u nich kanał RSS jest nieaktywny i można pobrać tylko jeden artykuł. Na stronie są dziesiątki artykułów i nie potrafię ich pobrać przez Calibri.
Pozdrawiam


29 mar 2012 21:55:02
Zobacz profil
Użytkownik

Dołączył(a): 04 kwi 2012 11:49:50
Posty: 1
eCzytnik: Kindle
Post Re: Polskie treści w calibre - komentarze
Witam,

czy można dodać recepty dla stron:

'Optyczne' http://www.optyczne.pl/rss.xml
'Fotopolis' http://www.fotopolis.pl/foto_rss.xml
'Świat Obrazu' http://www.swiatobrazu.pl/rss
'Fotoblogia' http://fotoblogia.pl/feed/rss2
'DPreview', http://www.dpreview.com/feeds/news/latest

Zrobiłem newsy z RSS-ów ale artykuły w nich nie są kompletne.

W repozytorium t3d jest optyczne_pl.recipe, tylko że nie mogę tej recepty dodać do mojego Calibre 0.8


04 kwi 2012 12:15:22
Zobacz profil
Użytkownik

Dołączył(a): 22 maja 2012 7:54:03
Posty: 2
eCzytnik: kindle
Post Re: Polskie treści w calibre - komentarze
A dało by się zrobić recepte na :

http://garfield.org.pl/

:mrgreen:


22 maja 2012 7:56:05
Zobacz profil
Użytkownik

Dołączył(a): 22 maja 2012 10:36:18
Posty: 1
eCzytnik: Kindle
Post Re: Polskie treści w calibre - komentarze
Hej, dorzucam receptę dla strony Drytooling.com.pl, która skupia się na wspinaczce zimowej. Czy możecie je dodać do listy?

http://drytooling.com.pl/pliki/drytooling.com.pl.recipe

http://drytooling.com.pl/pliki/favicon.ico

Opis strony

Drytooling.com.pl jest serwisem wspinaczki zimowej, alpinizmu i himalaizmu. Jeśli uwielbiasz zimę, nie możesz doczekać się aż wyciągniesz szpej z szafki i uderzysz w Tatry, Alpy, czy może Himalaje, to znajdziesz tutaj naprawdę dużo interesujących Cię treści! Zapraszamy!

Pozdrawiam serdecznie
Damian Granowski


22 maja 2012 10:40:31
Zobacz profil
Użytkownik

Dołączył(a): 15 wrz 2010 21:10:09
Posty: 3
Post Re: Polskie treści w calibre - komentarze
Czy można wykonać recepty dla magazynów: Estrada i Studio, Przekrój, Bloomberg Bussinesweek Polska, Film, Kino, Uważam Rze, Przegląd, Forum? Oczywiście w wolnym czasie, jesli ktoś posiada umiejętności, aby się specjalnie nie napracować przy tym :) Nie śpieszy mi się aż tak bardzo.


22 maja 2012 15:06:21
Zobacz profil
Admin

Dołączył(a): 13 cze 2008 14:47:02
Posty: 2835
Lokalizacja: Gdańsk
eCzytnik: kindle
Post Re: Polskie treści w calibre - komentarze
Uważam Rze na pewno nie, bo jak widać na ich stronach, dostęp do artykułów jest odpłatny.

_________________
Zgred - Rafał Ziemkiewicz napisał(a):
Dziś trzeba pisać o mieczach, czarach, toporach i wojowniczkach w blaszanych bikini, wszystko inne to już jest nisza w niszy. Albo o nastoletnich wampirach.
Porównywarka cen ebooków


22 maja 2012 15:57:23
Zobacz profil WWW
Wyświetl posty nie starsze niż:  Sortuj wg  
Utwórz nowy wątek Ten wątek jest zamknięty. Nie możesz w nim pisać ani edytować postów.  [ Posty: 242 ]  Przejdź na stronę Poprzednia strona  1 ... 13, 14, 15, 16, 17  Następna strona


Kto przegląda forum

Użytkownicy przeglądający to forum: Brak zalogowanych użytkowników i 0 gości


Nie możesz rozpoczynać nowych wątków
Nie możesz odpowiadać w wątkach
Nie możesz edytować swoich postów
Nie możesz usuwać swoich postów

Skocz do:  
cron