move comments around for pydocs functionality
This commit is contained in:
44
libs/sql.py
44
libs/sql.py
@@ -1,11 +1,14 @@
|
||||
import sqlite3
|
||||
from sqlite3 import Error
|
||||
|
||||
'''
|
||||
Custom SQL/database functions for WeirdAAL
|
||||
'''
|
||||
|
||||
import sqlite3
|
||||
from sqlite3 import Error
|
||||
|
||||
def create_table(db_name,table_name,sql):
|
||||
'''
|
||||
SQLite3 create table function
|
||||
'''
|
||||
with sqlite3.connect(db_name) as db:
|
||||
cursor = db.cursor()
|
||||
cursor.execute("""SELECT name FROM sqlite_master WHERE name=?""",(table_name,))
|
||||
@@ -29,6 +32,9 @@ def create_table(db_name,table_name,sql):
|
||||
|
||||
|
||||
def create_recon_table(db_name, table_name):
|
||||
'''
|
||||
Create recon table service:subservice:AWSKeyID,time
|
||||
'''
|
||||
sql = """CREATE TABLE recon
|
||||
(ID integer,
|
||||
service text,
|
||||
@@ -42,6 +48,9 @@ def create_recon_table(db_name, table_name):
|
||||
|
||||
|
||||
def create_awskey_table(db_name, table_name):
|
||||
'''
|
||||
Create awskey table (currently unused)
|
||||
'''
|
||||
sql = """CREATE TABLE AWSKey
|
||||
(ID integer,
|
||||
AWSKeyID Text,
|
||||
@@ -52,6 +61,9 @@ def create_awskey_table(db_name, table_name):
|
||||
|
||||
|
||||
def create_services_table(db_name, table_name):
|
||||
'''
|
||||
Create services table - service:sub_service:sub_service_data
|
||||
'''
|
||||
sql = """CREATE TABLE services
|
||||
(ID integer,
|
||||
AWSKeyID Text,
|
||||
@@ -65,35 +77,49 @@ def create_services_table(db_name, table_name):
|
||||
|
||||
|
||||
def insert_awskey_data(db_name, records):
|
||||
'''
|
||||
Insert AWS Key and a description to the AWSKey table (unused)
|
||||
'''
|
||||
sql = """INSERT INTO AWSKey(AWSKeyID, Description) VALUES (?,?)"""
|
||||
for record in records:
|
||||
query(db_name, sql,record)
|
||||
|
||||
|
||||
def insert_reconservice_data(db_name, records):
|
||||
'''
|
||||
Insert data into the recon table
|
||||
'''
|
||||
sql = """INSERT INTO recon(service, sub_service, AWSKeyID, checked_at) VALUES (?,?,?,?)"""
|
||||
for record in records:
|
||||
query(db_name,sql,record)
|
||||
|
||||
|
||||
def insert_sub_service_data(db_name, records):
|
||||
'''
|
||||
Insert service, sub_service & sub_service data into the DB
|
||||
'''
|
||||
sql = """INSERT INTO services(service, sub_service, sub_service_data, AWSKeyID, checked_at) VALUES (?,?,?,?,?)"""
|
||||
for record in records:
|
||||
query(db_name,sql,record)
|
||||
|
||||
|
||||
def search_recon_by_key(db_name,AWSKeyID):
|
||||
with sqlite3.connect(db_name) as db:
|
||||
cursor = db.cursor()
|
||||
cursor.execute("""SELECT DISTINCT service,sub_service,checked_at FROM recon WHERE AWSKeyID=? ORDER BY datetime(checked_at)""",(AWSKeyID,))
|
||||
results = cursor.fetchall()
|
||||
return results
|
||||
'''
|
||||
Function to query services by AWSKey and order them by time
|
||||
'''
|
||||
with sqlite3.connect(db_name) as db:
|
||||
cursor = db.cursor()
|
||||
cursor.execute("""SELECT DISTINCT service,sub_service,checked_at FROM recon WHERE AWSKeyID=? ORDER BY datetime(checked_at)""",(AWSKeyID,))
|
||||
results = cursor.fetchall()
|
||||
return results
|
||||
|
||||
|
||||
def query(db_name,sql,data):
|
||||
'''
|
||||
Generic query function
|
||||
'''
|
||||
with sqlite3.connect(db_name) as db:
|
||||
cursor = db.cursor()
|
||||
#cursor.execute("""PRAGMA foreign_keys = ON""")
|
||||
cursor.execute(sql,data)
|
||||
db.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user