Compare commits

..

2 Commits

Author SHA1 Message Date
d710dc723e add database models and session factory 2024-09-22 13:34:50 -04:00
59a11c97df chore: add .pylintrc 2024-09-22 13:34:01 -04:00
5 changed files with 57 additions and 1 deletions

2
.pylintrc Normal file
View File

@ -0,0 +1,2 @@
[FORMAT]
max-line-length = 120

0
harvester/db/__init__.py Normal file
View File

25
harvester/db/models.py Normal file
View File

@ -0,0 +1,25 @@
# harvester/db/models.py
from sqlalchemy import Column, Integer, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Proxy(Base):
__tablename__ = 'proxies'
id = Column(Integer, primary_key=True)
host = Column(String, nullable=False)
port = Column(Integer, nullable=False)
asn = Column(String)
egress_ip = Column(String)
egress_asn = Column(String)
date_added = Column(DateTime, nullable=False)
date_validated = Column(DateTime)
def __repr__(self):
return (
f'Proxy(id={self.id}, host={self.host}, port={self.port}, '
f'egress={self.egress}, created_at={self.created_at})'
)

28
harvester/db/session.py Normal file
View File

@ -0,0 +1,28 @@
# harvester/db/session.py
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
class SessionFactory:
def __init__(self, engine_url):
self.engine = create_engine(engine_url)
self.Session = sessionmaker(bind=self.engine)
def create_session(self):
return self.Session()
# Create a singleton instance of the SessionFactory
session_factory = None
def get_session_factory(engine_url):
global session_factory
if session_factory is None:
session_factory = SessionFactory(engine_url)
return session_factory
def get_session(engine_url):
return get_session_factory(engine_url).create_session()

View File

@ -1,2 +1,3 @@
requests
requests[socks]
sqlalchemy