# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai

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


class AdvancedUserRecipe1322322819(BasicNewsRecipe):
    title = u'GS24.pl (Głos Szczeciński)'
    description = u'Internetowy serwis Głosu Szczecińskiego'
    __author__ = u'Michał Szkutnik'
    __license__ = u'GPL v3'
    language = 'pl'
    publisher = 'Media Regionalne sp. z o.o.'
    category = 'news, szczecin'
    oldest_article = 2
    max_articles_per_feed = 100
    auto_cleanup = True
    cover_url = "http://www.gs24.pl/images/top_logo.png"

    feeds = [
        # (u'Wszystko', u'http://www.gs24.pl/rss.xml'),
        (u'Szczecin', u'http://www.gs24.pl/szczecin.xml'),
        (u'Stargard', u'http://www.gs24.pl/stargard.xml'),
        (u'Świnoujście', u'http://www.gs24.pl/swinoujscie.xml'),
        (u'Goleniów', u'http://www.gs24.pl/goleniow.xml'),
        (u'Gryfice', u'http://www.gs24.pl/gryfice.xml'),
        (u'Kamień Pomorski', u'http://www.gs24.pl/kamienpomorski.xml'),
        (u'Police', u'http://www.gs24.pl/police.xml'),
        (u'Region', u'http://www.gs24.pl/region.xml'),
        (u'Sport', u'http://www.gs24.pl/sport.xml'),
    ]

    def get_article_url(self, article):
        s = re.search("""/0L0S(gs24.*)/story01.htm""", article.link)
        s = s.group(1)
        replacements = {"0B": ".", "0C": "/",
                        "0H": ",", "0I": "_", "0D": "?", "0F": "="}
        for (a, b) in replacements.iteritems():
            s = string.replace(s, a, b)
        s = string.replace(s, "0A", "0")
        return "http://" + s

    def print_version(self, url):
        return url + "&Template=printpicart"
