Add initial database models and .gitignore file
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
.env
|
||||
venv
|
||||
@@ -0,0 +1,44 @@
|
||||
from sqlalchemy import create_engine, Column, Integer, String, Text, DateTime, Boolean
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from datetime import datetime
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
class WebsPorVisitar(Base):
|
||||
__tablename__ = 'webs_por_visitar'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
url = Column(String(2048), unique=True, nullable=False)
|
||||
agregado_en = Column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
prioridad = Column(Integer, default=1, nullable=False) # Prioridad para rastrear
|
||||
|
||||
class WebsVisitadas(Base):
|
||||
__tablename__ = 'webs_visitadas'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
url = Column(String(2048), unique=True, nullable=False)
|
||||
dominio = Column(String(255), nullable=False)
|
||||
titulo = Column(String(255), nullable=True)
|
||||
resumen = Column(Text, nullable=True)
|
||||
ip = Column(String(45), nullable=True) # IPv4 o IPv6
|
||||
fecha_creacion = Column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
codigo_http = Column(Integer, nullable=True) # Código de respuesta HTTP
|
||||
contenido_hash = Column(String(64), nullable=True) # Hash del contenido para detectar cambios
|
||||
es_dinamico = Column(Boolean, default=False) # Si es una página generada dinámicamente
|
||||
|
||||
# Crear el motor de base de datos y las tablas
|
||||
engine = create_engine('postgresql://usuario:password@localhost:5432/nombre_bd')
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
# Crear una sesión
|
||||
Session = sessionmaker(bind=engine)
|
||||
session = Session()
|
||||
|
||||
# Ejemplo de cómo agregar una entrada
|
||||
if __name__ == "__main__":
|
||||
nueva_web_por_visitar = WebsPorVisitar(url="http://example.com")
|
||||
session.add(nueva_web_por_visitar)
|
||||
session.commit()
|
||||
|
||||
print("Nueva URL agregada a 'webs_por_visitar'.")
|
||||
Reference in New Issue
Block a user