mirror of
https://gitea.phreedom.club/localhost_frssoft/FMN_bot
synced 2024-11-22 17:29:19 +02:00
localhost_frssoft
f46235ae22
* Parse imdb\kinopoisk limited * Кинопоиск всегда пытается резолвится через imdb базу * Improve append message
32 lines
983 B
Python
32 lines
983 B
Python
from src.imdb_datasets_worker import get_title_by_names_and_year
|
|
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:
|
|
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']))
|
|
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
|
|
|