Compare commits
2 Commits
980eadf588
...
d710dc723e
Author | SHA1 | Date | |
---|---|---|---|
d710dc723e | |||
59a11c97df |
0
harvester/db/__init__.py
Normal file
0
harvester/db/__init__.py
Normal file
25
harvester/db/models.py
Normal file
25
harvester/db/models.py
Normal 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
28
harvester/db/session.py
Normal 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()
|
@ -1,2 +1,3 @@
|
|||||||
requests
|
requests
|
||||||
requests[socks]
|
requests[socks]
|
||||||
|
sqlalchemy
|
Loading…
Reference in New Issue
Block a user