mirror of
https://git.phreedom.club/localhost_frssoft/FMN_bot.git
synced 2025-04-05 15:26:31 +02:00
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from src.imdb_datasets_worker import get_title_by_names_and_year
|
||
from loguru import logger
|
||
import requests
|
||
import time
|
||
|
||
|
||
kinopoisk_api_url='https://kinopoiskapiunofficial.tech/api/v2.2'
|
||
# Используется неофициальное API кинопоиска, дефолтный лимит 500 запросов.
|
||
|
||
with open(".auth_kinopoisk", mode='rt') as key_file:
|
||
token = key_file.read().replace('\n', '')
|
||
|
||
|
||
def get_kinopoisk_movie_to_imdb(film=list):
|
||
films_resolved = []
|
||
for i in film:
|
||
logger.debug(f'запрос id {i} у Кинопоиска')
|
||
headers = {
|
||
"X-API-KEY": token,
|
||
}
|
||
r = requests.get(kinopoisk_api_url + "/films/" + i, headers=headers)
|
||
if r.status_code == 200:
|
||
film_data = r.json()
|
||
logger.debug('КП ответил: ' + str(film_data))
|
||
|
||
films_resolved.append((film_data['nameOriginal'], film_data['nameRu'], film_data['year']))
|
||
else:
|
||
continue
|
||
time.sleep(0.2)
|
||
|
||
parsed_imdb_titles = get_title_by_names_and_year(films_resolved)
|
||
if parsed_imdb_titles != []:
|
||
logger.success('Найдены запрошенные фильмы КП у IMDB')
|
||
return parsed_imdb_titles
|
||
else:
|
||
logger.error('Запрошенные фильмы КП не найдены у IMDB ' + str(films_resolved))
|
||
|