Last active
September 10, 2025 04:20
-
-
Save alan80avalos/85c691dd3ebf574237dbb09b544b5de3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| #Separare el api: | |
| #"https://api.themoviedb.org/3/search/movie?include_adult=false&language=en-US&page=1" | |
| class BuscadorTMDB: | |
| def __init__(self, api_key): | |
| self.api_key = api_key | |
| self.base_url = "https://api.themoviedb.org/3/search/movie" | |
| def buscar(self, titulo): | |
| url = f"{self.base_url}?query={titulo}&include_adult=false&language=en-US&page=1" | |
| headers = { | |
| "accept": "application/json", | |
| "Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjYTQwNzJmZTJhYjU3OTA2ZDY0YTZhNzM5ZWMwYzM2ZiIsIm5iZiI6MTc1NzM3OTE4OC4zNzQsInN1YiI6IjY4YmY3YTc0NGFjZmUxNGU4ZTFiZDBlNyIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.IpcfZ-ECaO9ngPG5GfVwQyGONCJStOACK1Ss5pQhjYg" | |
| } | |
| #Donde se guarda la respuesta de la busqueda | |
| response = requests.get(url, headers=headers) | |
| if response.status_code == 200: | |
| return response.json()["results"] | |
| else: | |
| #Caso de error | |
| print("Error:", response.status_code, response.text) | |
| return [] | |
| class Pelicula: | |
| #Constructor que recibe un diccionario con los datos de la pelicula | |
| def __init__(self, data): | |
| self.titulo = data.get("title") | |
| self.fecha_estreno = data.get("release_date") | |
| self.descripcion = data.get("overview") | |
| self.poster_path = data.get("poster_path") | |
| #Metodo para mostrar la informacion de la pelicula | |
| def mostrarInfo(self): | |
| print("Title: ") | |
| print(self.titulo) | |
| print("Date of Release: ") | |
| print(self.fecha_estreno) | |
| print("Description: ") | |
| print(self.descripcion) | |
| if __name__ == "__main__": | |
| api_key = "eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjYTQwNzJmZTJhYjU3OTA2ZDY0YTZhNzM5ZWMwYzM2ZiIsIm5iZiI6MTc1NzM3OTE4OC4zNzQsInN1YiI6IjY4YmY3YTc0NGFjZmUxNGU4ZTFiZDBlNyIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.IpcfZ-ECaO9ngPG5GfVwQyGONCJStOACK1Ss5pQhjYg" | |
| buscador = BuscadorTMDB(api_key) | |
| titulo = input("Enter the title of the movie to search: ") | |
| resultados = buscador.buscar(titulo) | |
| peliculas = [Pelicula(data) for data in resultados] | |
| for pelicula in peliculas: | |
| pelicula.mostrarInfo() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @startuml | |
| actor Usuario | |
| participant Main | |
| participant BuscadorTMDB | |
| participant "API de TMDB" as APITMDB | |
| participant Pelicula | |
| Usuario -> Main: Ingresa título | |
| Main -> BuscadorTMDB: buscar(titulo de pelicula) | |
| BuscadorTMDB -> APITMDB: GET /search/movie | |
| APITMDB --> BuscadorTMDB: JSON con los resultados | |
| BuscadorTMDB --> Main: lista de resultados | |
| Main -> Pelicula: crea la instancia con datos | |
| Pelicula --> Main: objeto Pelicula | |
| Main -> Pelicula: mostrarInfo() | |
| Pelicula -> Usuario: imprime datos | |
| @enduml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @startuml | |
| class BuscadorTMDB { | |
| +api_key: String | |
| +base_url: String | |
| +init(api_key) | |
| +buscar(titulo): List | |
| } | |
| class Pelicula { | |
| +titulo: String | |
| +fecha_estreno: String | |
| +descripcion: String | |
| +poster_path: String | |
| +init(data) | |
| +mostrarInfo(): void | |
| } | |
| class Main { | |
| + main(): void | |
| } | |
| Main --> BuscadorTMDB : usa | |
| Main --> Pelicula : muestra la info | |
| BuscadorTMDB --> Pelicula : crea una instancia con los datos | |
| @enduml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -Alan: | |
| Como reflexión de esta actividad, eh tenido que aprender para llevarla acabo acerca de como gestionar APIs y | |
| como hacer peticiones “get” para que esta pueda regresarnos los datos que requerimos, otro punto que refine | |
| en cuanto a aprendizaje fue hacerla en Python que para mi es demasiado nuevo todo esto de trabajar con objetos | |
| con Python. Además, aprendí sobre que también se pueden realizar diagramas de secuencia en el software que | |
| habíamos trabajado antes para hacer el diagrama de clases. | |
| Erick: | |
| Este fue mi primer acercamiento al uso de las APIs, por lo que me ayudó mucho a familiarizarme con este concepto, | |
| especialmente al ponerlo en práctica y así poder ver como interactúan con el usuario, siento que lo que aprendí con | |
| esta tarea será muy importante para los temas que exploraremos a lo largo del semestre. Además de que me hace pensar | |
| en las formas en que podemos aprovechar más a fondo las ventajas del encapsulamiento que nos permite la programación | |
| orientada a objetos, en cómo se pueden usar muchas APIs en sinergia una con otra como en el ejemplo de la página de | |
| Amazon que vimos en una clase anterior. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment