feat: proxies are updated if already in database
This commit is contained in:
parent
5ac63e1fb5
commit
7b55220589
24
main.py
24
main.py
@ -59,14 +59,22 @@ def main():
|
||||
|
||||
# Save to DB
|
||||
session = session_factory.create_session()
|
||||
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)
|
||||
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(new_proxy)
|
||||
|
||||
session.commit()
|
||||
|
||||
# Create output directory if it does not exist
|
||||
|
Loading…
Reference in New Issue
Block a user