From f362265f9d07da22c991be519c4810b4ff4441fa Mon Sep 17 00:00:00 2001 From: MickSlash Date: Fri, 3 Apr 2020 19:24:31 +0000 Subject: [PATCH] Carica file su '' --- moviedb_api.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 moviedb_api.py diff --git a/moviedb_api.py b/moviedb_api.py new file mode 100644 index 0000000..b5fbd95 --- /dev/null +++ b/moviedb_api.py @@ -0,0 +1,60 @@ +import requests + +def get_film(endpoint,film,api_key,config_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"] + genres = data["results"][0]["genre_ids"] + # 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 + # print(data) + print(f"{nome_film}\n{descrizione_film}") + print(genres) + print(f"Immagine Poster : {poster_image} ") + return data + else: + print("Status Code : ",response.status_code) + print("Response Content : ",response.content) + raise Exception("C'é stato un errore!") + + + +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 + +if __name__ == "__main__": + 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?" + film = input("Inserisci un Film da Cercare : ") + config_data = get_configuration(configuration_url,api_key) + genre_data = get_genre(genre_url,api_key) + get_film(endpoint,film,api_key,config_data)