This script includes a function to query the database and prints the list of table names,as well a second function that accepts table name and number of rows as arguments and prints a summary of the head of each table.


In [1]:
import psycopg2
from auth_js import connection_string_js

In [2]:
#Connect to rds
try:
    conn = psycopg2.connect(connection_string_js)
except:
    print "\n_________CONNECTION FAILURE_________\n"
cur = conn.cursor()

In [3]:
#This function prints the names of the tables 
def table_lister ():
    cur.execute("""SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'""")
    rows = cur.fetchall()
    for row in rows:
        print row[0]

In [4]:
#This function prints columns and top rows from table, it accepts table name and number of rows as arguments.
def head_generator (table, limit):
    cur.execute("""SELECT * FROM %s LIMIT %s""" % (table, limit))
    col_names = [cn[0] for cn in cur.description]
    rows = cur.fetchall()
    print table
    print col_names
    for row in rows:
        print row
    print '\n'

In [ ]:
#Execute functions.
if __name__ == '__main__':
    table_lister()
    head_generator('flows',5)
    head_generator('redteam',5)
    head_generator('dns',5)
    head_generator('proc',5)
    head_generator('auth',5)

In [ ]:
#disconnect
cur.close()
conn.close()