-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
version 1.0, now will save encoded payloads into a database for futur…
…e use, you can view the database by running -vC
- Loading branch information
Showing
4 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
import sqlite3 | ||
|
||
import lib.settings | ||
|
||
|
||
def initialize(): | ||
if not os.path.exists(lib.settings.DATABASE_FILENAME): | ||
cursor = sqlite3.connect(lib.settings.DATABASE_FILENAME) | ||
cursor.execute( | ||
'CREATE TABLE "cached_payloads" (' | ||
'`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,' | ||
'`payload` TEXT NOT NULL' | ||
')' | ||
) | ||
conn = sqlite3.connect(lib.settings.DATABASE_FILENAME, isolation_level=None, check_same_thread=False) | ||
return conn.cursor() | ||
|
||
|
||
def fetch_payloads(cursor): | ||
try: | ||
cached_payloads = cursor.execute("SELECT * FROM cached_payloads") | ||
return cached_payloads.fetchall() | ||
except Exception as e: | ||
print e | ||
return [] | ||
|
||
|
||
def insert_payload(payload, cursor): | ||
try: | ||
is_inserted = False | ||
current_cache = fetch_payloads(cursor) | ||
id_number = len(current_cache) + 1 | ||
for item in current_cache: | ||
_, cache_payload = item | ||
if cache_payload == payload: | ||
is_inserted = True | ||
if not is_inserted: | ||
cursor.execute( | ||
"INSERT INTO cached_payloads (id,payload) VALUES (?,?)", (id_number, payload) | ||
) | ||
except Exception: | ||
return False | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters