Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions db/SqlHelper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# coding:utf-8
import datetime
import sqlalchemy
from sqlalchemy import Column, Integer, String, DateTime, Numeric, create_engine, VARCHAR
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
Expand Down Expand Up @@ -39,7 +40,7 @@ def __init__(self):
connect_args = {'check_same_thread': False}
self.engine = create_engine(DB_CONFIG['DB_CONNECT_STRING'], echo=False, connect_args=connect_args)
else:
self.engine = create_engine(DB_CONFIG['DB_CONNECT_STRING'], echo=False)
self.engine = create_engine(DB_CONFIG['DB_CONNECT_STRING'], echo=False, pool_size=20, pool_recycle=3600)
DB_Session = sessionmaker(bind=self.engine)
self.session = DB_Session()

Expand All @@ -54,8 +55,15 @@ def insert(self, value):
proxy = Proxy(ip=value['ip'], port=value['port'], types=value['types'], protocol=value['protocol'],
country=value['country'],
area=value['area'], speed=value['speed'])
self.session.add(proxy)
self.session.commit()
try:
self.session.add(proxy)
self.session.commit()
except sqlalchemy.exc.IntegrityError as e:
# catch duplicate entry error and init score with DEFAULT_SCORE
print(str(e))
self.session.rollback()
self.update({"ip": value['ip'], "port": value['port']}, {"score" :DEFAULT_SCORE})



def delete(self, conditions=None):
Expand Down