Repaired several bugs and database connection is setup and connects, scrapper just seems not to be scrapping just yet

This commit is contained in:
Dennis Eckerskorn 2024-12-08 18:05:39 +01:00
parent a645184cff
commit 277e4dcf1e
6 changed files with 21 additions and 14 deletions

Binary file not shown.

View File

@ -9,16 +9,23 @@ class Scrapper:
self.ui_instance = ui_instance
self.visited_links = set()
self.running=False
self.lock() = threading.Lock()
self.lock = threading.Lock()
#Configurar la base de datos para los enlaces
self.db_config = {
"host": "localhost",
"user": "root",
"password": "",
"database": "scrap_links_db",
"port": 3306
}
#Configurar la base de datos para los enlaces
self.db.config = {
"host": "localhost",
"user": "root",
"password": "1234Scrap",
"database": "scrap_links_db"
}
try:
connection = mysql.connector.connect(**self.db_config)
print("Conexion exitosa a base de datos")
connection.close()
except Exception as e:
print(f"Error al conectar a la base de datos: {e}")
def start_scraping(self):
"""Inicia el proceso de scraping"""
@ -61,11 +68,10 @@ class Scrapper:
text_widget = tab.text_widget
text_widget.insert("end", f"Enlaces encontrados en {url}:\n")
for link in links:
text_widget.insert("end", f" - {link}\n")
text_widget.insert("end", "\n")
text_widget.see("end")
text_widget.insert("end", f" - {link}\n")
text_widget.see("end")
def save_links_to_db(self, url, links)
def save_links_to_db(self, url, links):
"""Guarda los enlaces en la base de datos"""
try:
connection = mysql.connector(**self.db_config)
@ -75,6 +81,7 @@ class Scrapper:
cursor.execute("INSERT INTO links (url, parent_url) VALUES (%s, %s)", (link, url))
connection.commit()
cursor.close()
connection.close()
except:
print(f"Error al gaurdar en la base de datos")

View File

@ -22,7 +22,7 @@ class SystemMonitor:
},
"Processes": {
"data": [],
"fetch_func": lambda: self.get_process_count,
"fetch_func": self.get_process_count,
"interval": 1
}
}

View File

@ -102,7 +102,7 @@ class CenteredWindow(ctk.CTk):
start_button.pack(pady=5, padx=10)
stop_button = ctk.CTkButton(left_panel, text="Detener Scrapping", command=self.thread_manager.tasks["scrapper"].stop)
stop_button.pack("pady=5, padx=10")
stop_button.pack(pady=5, padx=10)