Exemplo n.º 1
0
    def actors(self, code):
        parser = ParserFilms()
        _temp = []
        _page = parser.get_html_topic(code)
        _page = ParserFilms.page_text(_page)

        for actor in self._data:
            if actor in _page:
                _temp.append(actor)
        return code, ', '.join(_temp)
Exemplo n.º 2
0
    def run(self):
        """Запуск потока"""
        with Pool(cpu_count()) as pool:
            _first_page_html = self.parser.get_html_by_url(self.f)  # html код первой страницы из категории
            _last_page_number = ParserFilms.get_last_page_number(_first_page_html)  # номер последней страницы lxml
            _temp = ParserFilms.get_list_pages_codes(_last_page_number)  # список кодов для параметра start
            _temp = pool.map(functools.partial(self.parser.get_html_by_url, self.f), _temp)  # хранение в ОП
            _temp = pool.map(ParserFilms.get_keys_descriptions_ratings, _temp)  # парсит данные lxml

        for info in _temp:
            self.result.update(info)
Exemplo n.º 3
0
def get_description(code):
    # Выводит описание фильма по введенному code
    _html = parser.get_html_topic(code)
    _page_text = ParserFilms.page_text(_html)
    _target = r'Описание:+(.*)Качество видео:+'
    _description = ParserFilms.searcher(_page_text, _target)
    _target = r'В ролях:+(.*)Описание:+'
    _actors = ParserFilms.searcher(_page_text, _target)
    if not _description:
        _description = 'Описание отсутсвует'
    if not _actors:
        _actors = 'Актёрский состав не найден'
    print('Code:', code, sep=' ')
    _temp = ('Описание: ' + _description).split('.')
    print('В ролях:', _actors, sep=' ')
    for line in _temp:
        if line:
            print(line.strip() + '.')
Exemplo n.º 4
0
def pic_url_parser(data=None):
    if not data:
        return
    parser = ParserFilms()
    keys = data.keys()

    with Pool(cpu_count()) as pool:
        pic_urls = pool.map(parser.get_pic_url, keys)

    for code, url in pic_urls:
        data[code]['pic_url'] = url
    return data
Exemplo n.º 5
0
import os
from datetime import datetime
from terminaltables import AsciiTable
import click

from engine import ParserFilms
from jsonworker import JsonWorker
from threads import ParserThread
from pic_url_parser import pic_url_parser

# from actors import ActorsParser
from config import ConfigWorker

parser = ParserFilms()  # Экземпляр класса ParserFilms
config = ConfigWorker()  # Экземпляр класса ConfigWorker
path = os.path.dirname(os.path.abspath(__file__))  # Путь до директории


def test_time(func):
    """Декоратор для тестирования времени выполнения кода"""
    def wrapper(*args, **kwargs):
        start = datetime.now()
        result = func(*args, **kwargs)
        end = datetime.now()
        total = end - start
        print('Время выполнения:', total, sep=' ')
        return result

    return wrapper

Exemplo n.º 6
0
class Services:
    def __init__(self):
        self._PATH = os.path.dirname(os.path.abspath(__file__))
        self._PARSER = ParserFilms()
        self._DATA = JsonWorker.json_to_dict('films_db.json')

    @staticmethod
    def config_get_option(path, section, option):
        _config = ConfigParser()
        _config.read(path)
        return _config.get(section, option)

    @staticmethod
    def counter_result_search(data, count=5):
        if not data:
            return
        result = {}
        temp = {}
        keys = list(data.keys())
        n = 1
        for i in range(len(keys)):
            key = keys[i]
            temp[key] = data.get(key)
            if (i + 1) % count == 0:
                result[n] = temp
                temp = {}
                n += 1
        result[n] = temp
        return result

    @staticmethod
    def description_splitter(description, symbol):
        result = description.split(symbol, 1)
        if len(result) < 2:
            return description, 'Краткое описание отсутствует'
        return result[0], f'({result[1]}'

    @staticmethod
    def poster(url):
        return f'<a href="{url}">&#8205;</a>'

    def search(self, words):
        if not words:
            return
        keys = words.split(' ')
        keys = list(filter(None, keys))
        result = JsonWorker.search_by(keys, self._DATA)
        if not result:
            return
        return result

    @staticmethod
    def file_in_directory(code, path):
        files = os.listdir(path)
        for file_name in files:
            if code in file_name:
                return file_name

    @staticmethod
    def get_empty_thumb_url():
        return 'https://t3.ftcdn.net/jpg/01/01/89/46/240_F_101894688_RVSZUtDfPR6Cr5eBDQI7Qo5pZ01jmyK3.jpg'

    def make_file(self, code):
        filename, received_file = self._PARSER.download_torrent_file(
            code,
            self._DATA.get(code)['Description'])
        file = BytesIO()
        file.name = f'{filename}.torrent'
        file.write(received_file)
        file.seek(0, 0)
        return file

    def get_name_by_code(self, code):
        return self._DATA.get(code)

    def top250(self):
        top250 = JsonWorker.json_to_dict(
            os.path.join(self._PATH, 'films_with_rating.json'))
        return top250
Exemplo n.º 7
0
 def __init__(self):
     self._PATH = os.path.dirname(os.path.abspath(__file__))
     self._PARSER = ParserFilms()
     self._DATA = JsonWorker.json_to_dict('films_db.json')