feat: proxies are updated if already in database

This commit is contained in:
agatha 2024-09-22 15:02:22 -04:00
parent 5ac63e1fb5
commit 7b55220589

12
main.py
View File

@ -59,14 +59,22 @@ def main():
# Save to DB
session = session_factory.create_session()
proxy = Proxy(
existing_proxy = session.query(Proxy).filter_by(host=proxy.split(':')[0],
port=int(proxy.split(':')[1])).first()
if existing_proxy:
existing_proxy.date_validated = datetime.now()
existing_proxy.egress_ip = ip
else:
new_proxy = Proxy(
host=proxy.split(':')[0],
port=int(proxy.split(':')[1]),
egress_ip=ip,
date_added=datetime.now(),
date_validated=datetime.now(),
)
session.add(proxy)
session.add(new_proxy)
session.commit()
# Create output directory if it does not exist