FMN_bot/src/kinopoisk_api.py

32 lines
983 B
Python
Raw Normal View History

from src.imdb_datasets_worker import get_title_by_names_and_year
2022-08-31 13:20:49 +03: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', '')
def get_kinopoisk_movie_to_imdb(film=list):
2022-08-31 13:20:49 +03:00
films_resolved = []
for i in film:
headers = {
"X-API-KEY": token,
}
r = requests.get(kinopoisk_api_url + "/films/" + i, headers=headers)
if r.status_code == 200:
film_data = r.json()
films_resolved.append((film_data['nameOriginal'], film_data['nameRu'], film_data['year']))
2022-08-31 13:20:49 +03:00
else:
continue
time.sleep(0.2)
parsed_imdb_titles = get_title_by_names_and_year(films_resolved)
if parsed_imdb_titles != []:
return parsed_imdb_titles
2022-08-31 13:20:49 +03:00