<commit_before># -*- coding: utf-8 -*-


import requests

from zitkino import formats, parsers
from zitkino.models import Cinema, Showtime, ScrapedFilm

from . import cinemas, scrapers


cinemas.register(
    name=u'RWE letní kino na Riviéře',
    url='http://www.kinonariviere.cz/',
    street=u'Bauerova 322/7',
    town=u'Brno',
    coords=(49.18827, 16.56924)
)


@scrapers.register
class Scraper(object):

    slug = 'brno_rwe_letni_kino_na_riviere'
    url = 'http://www.kinonariviere.cz/program'
    tags_map = {
        u'premiéra': 'premiere',
        u'titulky': 'subtitles',
    }

    def __init__(self):
        self.cinema = Cinema.objects.with_slug(self.slug).get()

    def __call__(self):
        for row in self._scrape_rows():
            yield self._parse_row(row, self.url)

    def _scrape_rows(self):
        resp = requests.get(self.url)
        html = formats.html(resp.text)
        return html.cssselect('.content table tr')

    def _parse_row(self, row, base_url):
        starts_at = parsers.date_time_year(
            row[1].text_content(),
            row[2].text_content()
        )

        title_main = row[3].text_content()
        title_orig = row[4].text_content()

        tags = [self.tags_map.get(t) for t
                in (row[5].text_content(), row[6].text_content())]

        price = parsers.price(row[7].text_content())
        url_booking = row[8].link(base_url)

        return Showtime(
            cinema=self.cinema,
            film_scraped=ScrapedFilm(
                title_main=title_main,
                titles=[title_main, title_orig],
            ),
            starts_at=starts_at,
            tags=tags,
            url_booking=url_booking,
            price=price,
        )
<commit_msg>Fixed scraper so it has no state.<commit_after># -*- coding: utf-8 -*-


import requests

from zitkino import formats, parsers
from zitkino.models import Cinema, Showtime, ScrapedFilm

from . import cinemas, scrapers


cinemas.register(
    name=u'RWE letní kino na Riviéře',
    url='http://www.kinonariviere.cz/',
    street=u'Bauerova 322/7',
    town=u'Brno',
    coords=(49.18827, 16.56924)
)


@scrapers.register
class Scraper(object):

    slug = 'brno_rwe_letni_kino_na_riviere'
    url = 'http://www.kinonariviere.cz/program'
    tags_map = {
        u'premiéra': 'premiere',
        u'titulky': 'subtitles',
    }

    def __call__(self):
        cinema = Cinema.objects.with_slug(self.slug).get()
        for row in self._scrape_rows():
            showtime = self._parse_row(row, self.url)
            showtime.cinema = cinema
            yield showtime

    def _scrape_rows(self):
        resp = requests.get(self.url)
        html = formats.html(resp.text)
        return html.cssselect('.content table tr')

    def _parse_row(self, row, base_url):
        starts_at = parsers.date_time_year(
            row[1].text_content(),
            row[2].text_content()
        )

        title_main = row[3].text_content()
        title_orig = row[4].text_content()

        tags = [self.tags_map.get(t) for t
                in (row[5].text_content(), row[6].text_content())]

        price = parsers.price(row[7].text_content())
        url_booking = row[8].link(base_url)

        return Showtime(
            film_scraped=ScrapedFilm(
                title_main=title_main,
                titles=[title_main, title_orig],
            ),
            starts_at=starts_at,
            tags=tags,
            url_booking=url_booking,
            price=price,
        )

{'fraction_non_alphanumeric': 0.1220617388841688, 'fraction_numerical': 0.015293118096856415, 'mean_word_length': 2.243342516069789, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5038650', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1203, 'n_words': 209}