示例#1
0
def echo_search_by_keys(keys):
    """Поиск по ключевым словам"""
    result = JsonWorker.search_by(keys)
    if not result:
        return
    films_echo(result)
    JsonWorker.dict_to_json(os.path.join(path, 'files\\temp.json'), result)
示例#2
0
def update_db():
    # Обновление базы данных фильмов
    click.echo(
        'Обновление базы данных, подождите это займёт несколько минут...')

    # data = main()
    # print(f'Всего раздач {len(data)}')
    # JsonWorker.dict_to_json(os.path.join(path, 'files\\films_db.json'), data)
    # JsonWorker.dict_to_json(os.path.join(path, 'files\\films_db.json'), update_db_in_ram())

    update_db_in_ram()
    print('Сортировка ...')
    data = JsonWorker.json_to_dict(os.path.join(path, 'files\\films_db.json'))
    print('Всего раздач:', len(data), sep=' ')
    JsonWorker.dict_to_json(os.path.join(path, 'files\\films_db.json'),
                            sort_dict_by_value(data))
示例#3
0
 def parse_actors(self):
     new_actor_codes = JsonWorker.sub_json(
         self.path + '\\files\\actors.json',
         self.path + '\\files\\films_db.json')
     new_torrents = None
     if new_actor_codes:
         new_torrents = ActorsParser.echo_new_films(
             new_actor_codes,
             JsonWorker.json_to_dict(self.path + '\\files\\films_db.json'))
     print('Добавлено новых раздач:', len(new_actor_codes), sep=' ')
     data = JsonWorker.json_to_dict(
         os.path.join(self.path, 'files\\actors.json'))
     with Pool(cpu_count()) as pool:
         actors = pool.map(self.actors, new_actor_codes)
     for actor in actors:
         data[actor[0]] = actor[1]
     JsonWorker.dict_to_json(os.path.join(self.path, 'files\\actors.json'),
                             data)
     return new_torrents
示例#4
0
def update_db_in_ram():
    """Загрузка спарсенных данных в ОП"""
    topics = config.get_ini_dict('Topics').keys()
    workers = []
    data = {}
    for f in topics:
        thread = ParserThread(f, parser)
        thread.daemon = False
        thread.start()
        workers.append(thread)
    for t in workers:
        t.join()
        data.update(t.get_result())
        print('Обновленно')

    new_torrent = JsonWorker.new_torrent_topics(
        os.path.join(path, 'files\\films_db.json'), data)
    updated_data = pic_url_parser(data=new_torrent)
    films_echo(updated_data)
    JsonWorker.dict_to_json(os.path.join(path, 'files\\new_torrent.json'),
                            updated_data)
    JsonWorker.update_dict_in_json(os.path.join(path, 'files\\films_db.json'),
                                   updated_data)
示例#5
0
def download_torrent_file(codes, _all):
    """Загружает торрент файлы по ключам"""
    if _all:
        data = JsonWorker.json_to_dict(os.path.join(path, 'files\\temp.json'))
        if not data:
            print('Файл temp.json пуст')
            return
        codes = data.keys()
    else:
        data = JsonWorker.json_to_dict(
            os.path.join(path, 'files\\films_db.json'))

    with click.progressbar(codes,
                           label='Сохранение torrent файлов',
                           empty_char='.') as bar:
        for code in bar:
            if code not in data.keys():
                print('Фильма с ключом:', code, 'нет в базе данных', sep=' ')
                return
            parser.download_torrent_file(code, data.get(code)['Description'])

    JsonWorker.dict_to_json(os.path.join(path, 'files\\temp.json'), None)
    click.echo('Загрузка файлов успешно завершена')