~ubuntu-branches/debian/sid/calibre/sid

« back to all changes in this revision

Viewing changes to recipes/fronda.recipe

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2014-05-14 18:17:50 UTC
  • mfrom: (1.5.10)
  • Revision ID: package-import@ubuntu.com-20140514181750-xyrxqa47dbw0qfhu
Tags: 1.36.0+dfsg-1
* New upstream release:
  - Fixes editing of metadata (Closes: #741638)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env  python
2
 
 
3
 
__license__   = 'GPL v3'
4
 
__copyright__ = u'2010-2013, Tomasz Dlugosz <tomek3d@gmail.com>'
5
 
'''
6
 
fronda.pl
7
 
'''
8
 
 
9
 
import re
10
 
from calibre.web.feeds.news import BasicNewsRecipe
11
 
from datetime import timedelta, date
12
 
 
13
 
class Fronda(BasicNewsRecipe):
14
 
    title          = u'Fronda.pl'
15
 
    publisher      = u'Fronda.pl'
16
 
    description    = u'Portal po\u015bwi\u0119cony - Informacje'
17
 
    language = 'pl'
18
 
    __author__ = u'Tomasz D\u0142ugosz'
19
 
    oldest_article = 7
20
 
    max_articles_per_feed = 100
21
 
    use_embedded_content = False
22
 
    no_stylesheets = True
23
 
 
24
 
    extra_css = '''
25
 
        h1 {font-size:150%}
26
 
        .body {text-align:left;}
27
 
        div#featured-image {font-style:italic; font-size:70%}
28
 
    '''
29
 
 
30
 
    earliest_date = date.today() - timedelta(days=oldest_article)
31
 
 
32
 
    def date_cut(self,datestr):
33
 
        # eg. 5.11.2012, 12:07
34
 
        timestamp = datestr.split(',')[0]
35
 
        parts = timestamp.split('.')
36
 
        art_date = date(int(parts[2]),int(parts[1]),int(parts[0]))
37
 
        return True if art_date < self.earliest_date else False
38
 
 
39
 
    def parse_index(self):
40
 
        genres = [
41
 
            ('ekonomia,4.html', 'Ekonomia'),
42
 
            ('filozofia,15.html', 'Filozofia'),
43
 
            ('historia,6.html', 'Historia'),
44
 
            ('kosciol,8.html', 'Kościół'),
45
 
            ('kultura,5.html', 'Kultura'),
46
 
            ('media,10.html', 'Media'),
47
 
            ('nauka,9.html', 'Nauka'),
48
 
            ('polityka,11.html', 'Polityka'),
49
 
            ('polska,12.html', 'Polska'),
50
 
            ('prolife,3.html', 'Prolife'),
51
 
            ('religia,7.html', 'Religia'),
52
 
            ('rodzina,13.html', 'Rodzina'),
53
 
            ('swiat,14.html', 'Świat'),
54
 
            ('wydarzenie,16.html', 'Wydarzenie')
55
 
        ]
56
 
        feeds = []
57
 
        articles = {}
58
 
 
59
 
        for url, genName in genres:
60
 
            try:
61
 
                soup = self.index_to_soup('http://www.fronda.pl/c/'+ url)
62
 
            except:
63
 
                continue
64
 
            articles[genName] = []
65
 
            for item in soup.findAll('li'):
66
 
                article_h = item.find('h2')
67
 
                if not article_h:
68
 
                    continue
69
 
                article_date = self.tag_to_string(item.find('b'))
70
 
                if self.date_cut(article_date):
71
 
                    continue
72
 
                article_a = article_h.find('a')
73
 
                article_url = 'http://www.fronda.pl' + article_a['href']
74
 
                article_title = self.tag_to_string(article_a)
75
 
                articles[genName].append( { 'title' : article_title, 'url' : article_url, 'date' : article_date })
76
 
            if articles[genName]:
77
 
                feeds.append((genName, articles[genName]))
78
 
        return feeds
79
 
 
80
 
    keep_only_tags = [
81
 
        dict(name='div', attrs={'class':'yui-g'})
82
 
        ]
83
 
 
84
 
    remove_tags = [
85
 
        dict(name='div', attrs={'class':['related-articles','button right','pagination','related-articles content']}),
86
 
        dict(name='h3', attrs={'class':'block-header article comments'}),
87
 
        dict(name='ul', attrs={'class':['comment-list','category','tag-list']}),
88
 
        dict(name='p', attrs={'id':'comments-disclaimer'}),
89
 
        dict(name='div', attrs={'style':'text-align: left; margin-bottom: 15px;'}),
90
 
        dict(name='div', attrs={'style':'text-align: left; margin-top: 15px; margin-bottom: 30px;'}),
91
 
        dict(name='div', attrs={'id':'comment-form'}),
92
 
        dict(name='span', attrs={'class':'separator'})
93
 
        ]
94
 
 
95
 
    preprocess_regexps = [
96
 
        (re.compile(r'komentarzy: .*?</h6>', re.IGNORECASE | re.DOTALL | re.M ), lambda match: '</h6>')]