import requests import re api_key = "7aa61de81426820176ddbd64dca0485f" endpoint = "https://api.themoviedb.org/3/search/movie?" configuration_url = "https://api.themoviedb.org/3/configuration?" genre_url = "https://api.themoviedb.org/3/genre/movie/list?" # config_data = get_configuration(configuration_url,api_key) # genre_data = get_genre(genre_url,api_key) # get_film(endpoint,film,api_key,config_data,genre_data) def get_film(endpoint,film,api_key,config_data,genre_data): language = "it-IT" payloads = {"api_key":api_key,"language":language,"query":film} response = requests.get(endpoint, params=payloads) if response.ok: data = response.json() # contatore = 0 nome_film = data["results"][0]["title"] nome_originale = data["results"][0]["original_title"] descrizione_film = data["results"][0]["overview"] poster_path = data["results"][0]["poster_path"] background_path = data["results"][0]["backdrop_path"] genres = data["results"][0]["genre_ids"] release_date = data["results"][0]["release_date"] data_rilascio = re.search('(^.{4})',release_date) year = data_rilascio.group(1) # for films in data["results"]: # contatore += 1 # print(contatore,films["title"]) # print("Descrizione :") # print(films["overview"]) img_base_secure_url = config_data["images"]["secure_base_url"] poster_size = config_data["images"]["poster_sizes"][6] poster_image = img_base_secure_url + poster_size + poster_path background_size = config_data["images"]["backdrop_sizes"][3] background_image = img_base_secure_url + background_size + background_path # print(data) # lista_generi_film = [] lista_generi_film = [] for generi in genre_data['genres']: # print(generi['name']) id_generi = generi['id'] if id_generi in genres: lista_generi_film.append(generi['name']) # print(genres) return nome_film,descrizione_film,lista_generi_film,poster_image,background_image,year else: print("Status Code : ",response.status_code) print("Response Content : ",response.content) raise Exception("C'é stato un errore nella Funzione Film!") def get_configuration(configuration_url,api_key): api_configuration = {"api_key":api_key} response = requests.get(configuration_url,params=api_configuration) if response.ok: config_data = response.json() # print(config_data) return config_data def get_genre(genre_url,api_key): language = "it-IT" genre_api = {"api_key":api_key,"language":language} response = requests.get(genre_url,params=genre_api) if response.ok: genre_data = response.json() # print(genre_data) return genre_data config_data = get_configuration(configuration_url,api_key) genre_data = get_genre(genre_url,api_key)