import re

from calibre.web.feeds.news import BasicNewsRecipe

class FocusRecipe(BasicNewsRecipe):
    __license__ = 'GPL v3'
    __author__ = u'Artur Stachecki <artur.stachecki@gmail.com>'
    language = 'pl'
    version = 1

    title = u'Money.pl'
    category = u'News'
    description = u'Informacje finansowe z kraju i ze świata. Aktualne i archiwalne: notowania giełdowe, kursy walut, wskaźniki gospodarcze.'
    remove_empty_feeds= True
    no_stylesheets=True
    oldest_article = 1
    max_articles_per_feed = 100000
    recursions = 0

    no_stylesheets = True
    remove_javascript = True

    simultaneous_downloads = 2

    r = re.compile('.*(?P<url>http:\/\/(www.money.pl)|(rss.feedsportal.com\/c)\/.*\.html?).*')
    keep_only_tags =[]
    keep_only_tags.append(dict(name = 'div', attrs = {'class' : 'artykul'}))
    remove_tags    = [dict(name='ul', attrs={'class':'socialStuff'})]

    extra_css = '''
                    body {font-family: Arial,Helvetica,sans-serif ;}
                    h1{text-align: left;}
                    h2{font-size: medium; font-weight: bold;}
                    p.lead {font-weight: bold; text-align: left;}
                    .authordate {font-size: small; color: #696969;}
                    .fot{font-size: x-small; color: #666666;}
                    '''

    feeds          = [
                            ('Wiadomosci z kraju', 'http://money.pl.feedsportal.com/c/33900/f/612847/index.rss'),
                            ('Wiadomosci ze swiata', 'http://money.pl.feedsportal.com/c/33900/f/612848/index.rss'),
                            ('Gospodarka', 'http://money.pl.feedsportal.com/c/33900/f/612849/index.rss'),
                            ('Waluty', 'http://money.pl.feedsportal.com/c/33900/f/612850/index.rss'),
                            ('Gielda', 'http://money.pl.feedsportal.com/c/33900/f/612851/index.rss'),
                            ('Banki', 'http://money.pl.feedsportal.com/c/33900/f/612852/index.rss'),
                            ('Fundusze', 'http://money.pl.feedsportal.com/c/33900/f/612853/index.rss'),
                            ('Emerytury', 'http://money.pl.feedsportal.com/c/33900/f/612854/index.rss'),
                            ('Podatki', 'http://money.pl.feedsportal.com/c/33900/f/612855/index.rss'),
                            ('Ubezpieczenia', 'http://money.pl.feedsportal.com/c/33900/f/612856/index.rss'),
                            ('Poradniki', 'http://money.pl.feedsportal.com/c/33900/f/612857/index.rss'),
                            ('Raporty', 'http://money.pl.feedsportal.com/c/33900/f/612858/index.rss'),
                            ('Motoryzacja', 'http://money.pl.feedsportal.com/c/33900/f/612859/index.rss'),
                            ('Manager', 'http://money.pl.feedsportal.com/c/33900/f/612860/index.rss'),
                            ('Dla firm', 'http://money.pl.feedsportal.com/c/33900/f/612861/index.rss'),
                            ('Prawo', 'http://money.pl.feedsportal.com/c/33900/f/612862/index.rss'),
                            ('Nieruchomosci', 'http://money.pl.feedsportal.com/c/33900/f/612863/index.rss'),
                            ('Praca', 'http://money.pl.feedsportal.com/c/33900/f/612864/index.rss'),


                           ]

    def print_version(self, url):
        if url.count ('money.pl.feedsportal.com'):
            u = url.find('0Cartykul0C')
            u = 'http://www.m.money.pl/wiadomosci/artykul/' + url[u + 21:]
            u = u.replace('0C', '/')
            u = u.replace('A', '')
            u = u.replace ('0E','-')
            u = u.replace ('0P',';')
            u = u.replace ('0H',',')
            u = u.replace ('0B','.')
            u = u.replace (',0,',',-1,')
            u = u.replace('0Tutm0Isource0Frss0Gutm0Imedium0Frss0Gutm0Icampaign0Frss/story01.htm', '')
        else:
            u = url.replace('/nc/1','/do-druku/1')
        return u
