2022-09-04 01:32:25 +02:00
|
|
|
|
from src.imdb_datasets_worker import get_title_by_names_and_year
|
2022-09-10 22:31:23 +02:00
|
|
|
|
from loguru import logger
|
2022-08-31 12:20:49 +02:00
|
|
|
|
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', '')
|
|
|
|
|
|
|
|
|
|
|
2022-09-04 01:32:25 +02:00
|
|
|
|
def get_kinopoisk_movie_to_imdb(film=list):
|
2022-08-31 12:20:49 +02:00
|
|
|
|
films_resolved = []
|
|
|
|
|
for i in film:
|
2022-09-10 22:31:23 +02:00
|
|
|
|
logger.debug(f'запрос id {i} у Кинопоиска')
|
2022-08-31 12:20:49 +02:00
|
|
|
|
headers = {
|
|
|
|
|
"X-API-KEY": token,
|
|
|
|
|
}
|
|
|
|
|
r = requests.get(kinopoisk_api_url + "/films/" + i, headers=headers)
|
|
|
|
|
if r.status_code == 200:
|
|
|
|
|
film_data = r.json()
|
2022-09-11 23:13:21 +02:00
|
|
|
|
logger.debug('КП ответил: ' + str(film_data))
|
2022-09-04 01:32:25 +02:00
|
|
|
|
|
|
|
|
|
films_resolved.append((film_data['nameOriginal'], film_data['nameRu'], film_data['year']))
|
2022-08-31 12:20:49 +02:00
|
|
|
|
else:
|
|
|
|
|
continue
|
|
|
|
|
time.sleep(0.2)
|
2022-09-04 01:32:25 +02:00
|
|
|
|
|
|
|
|
|
parsed_imdb_titles = get_title_by_names_and_year(films_resolved)
|
|
|
|
|
if parsed_imdb_titles != []:
|
2022-09-10 22:31:23 +02:00
|
|
|
|
logger.success('Найдены запрошенные фильмы КП у IMDB')
|
2022-09-04 01:32:25 +02:00
|
|
|
|
return parsed_imdb_titles
|
2022-09-10 22:31:23 +02:00
|
|
|
|
else:
|
2022-09-11 23:13:21 +02:00
|
|
|
|
logger.error('Запрошенные фильмы КП не найдены у IMDB ' + str(films_resolved))
|
2022-08-31 12:20:49 +02:00
|
|
|
|
|