Skip to content

Commit

Permalink
Merge pull request #63 from d-Rickyy-b/fix-sqlite-conn
Browse files Browse the repository at this point in the history
Fix sqlite issues
  • Loading branch information
d-Rickyy-b committed Sep 3, 2019
2 parents cc7edf4 + f47ec62 commit a0e2d67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 11 additions & 3 deletions pastepwn/core/pastepwn.py
Expand Up @@ -12,7 +12,13 @@

class PastePwn(object):

def __init__(self, database=None, proxies=None):
def __init__(self, database=None, proxies=None, store_all_pastes=True):
"""
Basic PastePwn object handling the connection to pastebin and all the analyzers and actions
:param database: Database object extending AbstractDB
:param proxies: Dict of proxies as defined in the requests documentation
:param store_all_pastes: Bool to decide if all pastes should be stored into the db
"""
self.logger = logging.getLogger(__name__)
self.database = database
self.paste_queue = Queue()
Expand All @@ -36,14 +42,16 @@ def __init__(self, database=None, proxies=None):
self.action_handler = ActionHandler(action_queue=self.action_queue,
exception_event=self.__exception_event)

if self.database is not None:
if self.database is not None and store_all_pastes:
# Save every paste to the database with the AlwaysTrueAnalyzer
self.logger.info("Database provided! Storing pastes in there.")
database_action = DatabaseAction(self.database)
always_true = AlwaysTrueAnalyzer(database_action)
self.add_analyzer(always_true)
else:
elif store_all_pastes:
self.logger.info("No database provided!")
else:
self.logger.info("Not storing all pastes!")

def add_scraper(self, scraper):
scraper.init_exception_event(self.__exception_event)
Expand Down
5 changes: 3 additions & 2 deletions pastepwn/database/sqlitedb.py
Expand Up @@ -21,7 +21,7 @@ def __init__(self, dbpath="pastepwn"):
open(self.dbpath, "a").close()

try:
self.db = sqlite3.connect(dbpath)
self.db = sqlite3.connect(dbpath, check_same_thread=False)
self.db.text_factory = lambda x: str(x, 'utf-8', "ignore")
self.cursor = self.db.cursor()
self._create_tables()
Expand All @@ -41,6 +41,7 @@ def _create_tables(self):
'size' INTEGER,
'date' INTEGER,
'expire' INTEGER,
'syntax' TEXT,
'scrape_url' TEXT,
'full_url' TEXT,
'body' TEXT,
Expand All @@ -49,7 +50,7 @@ def _create_tables(self):

def _insert_data(self, paste):
self.cursor.execute("INSERT INTO pastes (key, title, user, size, date, expire, syntax, scrape_url, full_url, body) "
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(paste.key,
paste.title,
paste.user,
Expand Down

0 comments on commit a0e2d67

Please sign in to comment.