parent
aab11b8ba7
commit
e87f33d1f9
|
@ -0,0 +1,15 @@
|
|||
from models.Screen import Modelo
|
||||
from VistaMain import Vista
|
||||
|
||||
class Controlador:
|
||||
def __init__(self, modelo, vista):
|
||||
self.modelo = modelo
|
||||
self.vista = vista
|
||||
|
||||
# Conectar los botones con sus respectivos frames
|
||||
self.vista.button1.config(command=lambda: self.vista.mostrar_frame("frame1"))
|
||||
self.vista.button2.config(command=lambda: self.vista.mostrar_frame("frame2"))
|
||||
self.vista.button3.config(command=lambda: self.vista.mostrar_frame("frame3"))
|
||||
|
||||
# Mostrar el frame inicial
|
||||
self.vista.mostrar_frame("frame1")
|
|
@ -0,0 +1,11 @@
|
|||
import tkinter as tk
|
||||
from models.Screen import Modelo
|
||||
from VistaMain import Vista
|
||||
from ControllerMain import Controlador
|
||||
|
||||
if __name__ == "__main__":
|
||||
root = tk.Tk()
|
||||
modelo = Modelo()
|
||||
vista = Vista(root)
|
||||
controlador = Controlador(modelo, vista)
|
||||
root.mainloop()
|
|
@ -0,0 +1,57 @@
|
|||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
class Vista:
|
||||
def __init__(self, root):
|
||||
self.root = root
|
||||
self.root.title("Ventana con Botones y Frame")
|
||||
self.root.geometry("1280x720")
|
||||
self.root.configure(bg="#d3eaf2")
|
||||
|
||||
self.crear_estilo()
|
||||
self.crear_frames()
|
||||
self.crear_botones()
|
||||
|
||||
def crear_estilo(self):
|
||||
self.style = ttk.Style()
|
||||
self.style.configure("TButton", font=("Arial", 16), padding=10, background="#007acc", foreground="#ffffff")
|
||||
self.style.map("TButton", background=[("active", "#005f99")], foreground=[("active", "#ffffff")])
|
||||
|
||||
def crear_frames(self):
|
||||
self.main_frame = tk.Frame(self.root)
|
||||
self.main_frame.pack(fill="both", expand=True)
|
||||
|
||||
self.menu_frame = tk.Frame(self.main_frame, width=200, background="#f0f0f0", relief="sunken", borderwidth=2)
|
||||
self.menu_frame.pack(side="left", fill="y")
|
||||
|
||||
self.content_frame = tk.Frame(self.main_frame, relief="sunken", borderwidth=5, background="#ffffff")
|
||||
self.content_frame.pack(side="left", expand=True, fill="both", padx=20, pady=20)
|
||||
|
||||
# Crear múltiples frames dentro del área de contenido
|
||||
self.frames = {
|
||||
"frame1": tk.Frame(self.content_frame, background="#ffdddd"),
|
||||
"frame2": tk.Frame(self.content_frame, background="#ddffdd"),
|
||||
"frame3": tk.Frame(self.content_frame, background="#ddddff"),
|
||||
}
|
||||
|
||||
for frame in self.frames.values():
|
||||
frame.place(relwidth=1, relheight=1) # Superponer frames
|
||||
|
||||
def crear_botones(self):
|
||||
self.button_frame = ttk.Frame(self.root, padding=10)
|
||||
self.button_frame.pack(side="top", fill="x")
|
||||
|
||||
self.button1 = ttk.Button(self.button_frame, text="B1", style="TButton")
|
||||
self.button2 = ttk.Button(self.button_frame, text="B2", style="TButton")
|
||||
self.button3 = ttk.Button(self.button_frame, text="B3", style="TButton")
|
||||
|
||||
self.button1.pack(side="left", expand=True, fill="both", padx=5, pady=5)
|
||||
self.button2.pack(side="left", expand=True, fill="both", padx=5, pady=5)
|
||||
self.button3.pack(side="left", expand=True, fill="both", padx=5, pady=5)
|
||||
|
||||
def mostrar_frame(self, frame_name):
|
||||
# Ocultar todos los frames
|
||||
for frame in self.frames.values():
|
||||
frame.lower()
|
||||
# Mostrar el frame seleccionado
|
||||
self.frames[frame_name].lift()
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,63 @@
|
|||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from urllib.parse import urljoin
|
||||
from pymongo import MongoClient
|
||||
|
||||
|
||||
class ScraperModel:
|
||||
def __init__(self):
|
||||
self.to_visit = []
|
||||
self.visited = set()
|
||||
|
||||
# Conexión a MongoDB
|
||||
self.client = MongoClient("mongodb://localhost:27017/")
|
||||
self.db = self.client["scraping"]
|
||||
self.collection = self.db["visited_links"]
|
||||
|
||||
# Crear índice único para evitar duplicados
|
||||
self.collection.create_index("url", unique=True)
|
||||
|
||||
def add_url(self, url):
|
||||
"""Añade una URL a la lista de pendientes."""
|
||||
if url not in self.visited and url not in self.to_visit:
|
||||
self.to_visit.append(url)
|
||||
|
||||
def scrape_next_url(self):
|
||||
"""Scrapea la siguiente URL."""
|
||||
if not self.to_visit:
|
||||
return None, []
|
||||
|
||||
current_url = self.to_visit.pop(0)
|
||||
self.visited.add(current_url)
|
||||
|
||||
try:
|
||||
# Solicitar la URL
|
||||
response = requests.get(current_url, timeout=10)
|
||||
response.raise_for_status()
|
||||
except requests.RequestException as e:
|
||||
return current_url, f"Error al acceder a {current_url}: {e}"
|
||||
|
||||
# Procesar los enlaces encontrados
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
found_links = []
|
||||
|
||||
for link in soup.find_all('a', href=True):
|
||||
full_url = urljoin(current_url, link['href'])
|
||||
if full_url not in self.visited and full_url not in self.to_visit:
|
||||
self.to_visit.append(full_url)
|
||||
found_links.append(full_url)
|
||||
|
||||
# Guardar URL visitada en MongoDB
|
||||
self.save_to_database(current_url)
|
||||
return current_url, found_links
|
||||
|
||||
def save_to_database(self, url):
|
||||
"""Guarda la URL visitada en la base de datos."""
|
||||
try:
|
||||
self.collection.insert_one({"url": url})
|
||||
except Exception as e:
|
||||
print(f"Error al guardar en la base de datos: {e}")
|
||||
|
||||
def has_pending_urls(self):
|
||||
"""Verifica si hay URLs pendientes."""
|
||||
return bool(self.to_visit)
|
|
@ -0,0 +1,6 @@
|
|||
class Modelo:
|
||||
def __init__(self):
|
||||
self.contenido = "Selecciona un botón para mostrar contenido"
|
||||
|
||||
def obtener_contenido(self, boton):
|
||||
return f"Contenido del Botón {boton}"
|
Binary file not shown.
|
@ -0,0 +1,15 @@
|
|||
import tkinter as tk
|
||||
|
||||
root = tk.Tk()
|
||||
root.geometry("400x300")
|
||||
|
||||
# Crear un frame
|
||||
frame = tk.Frame(root, width=300, height=200, bg="lightblue", relief="sunken", borderwidth=2)
|
||||
frame.pack(padx=10, pady=10)
|
||||
|
||||
# Agregar widgets al frame
|
||||
label = tk.Label(frame, text="Soy un label dentro del frame", bg="lightblue")
|
||||
label.pack(pady=20)
|
||||
|
||||
# Iniciar la ventana
|
||||
root.mainloop()
|
Loading…
Reference in New Issue