コード例 #1
0
def insert_record(conf, response_code, response_time, valid, timechecked):
    conn = None
    try:
        conn = get_conn()
        cursor = get_cursor(conn)
        cursor.execute(
            "INSERT INTO sites_stats(site_id, response_code, timestamp, response_time, response_pass) VALUES(%s, %s, TIMESTAMP %s, %s, %s)",
            (conf.id, response_code, str(timechecked), int(
                response_time * 1000), valid))
        conn.commit()
        print("Committed rows")
        cursor.close()
    except (Exception, psycopg2.DatabaseError) as e:
        print(e)
    finally:
        if conn is not None:
            conn.close()  # Closing connection should close cursor as well.
コード例 #2
0
def get_sites(conn=None, cursor=None):
    list_of_sites = []
    try:
        if not conn or not cursor:
            conn = get_conn()
            cursor = get_cursor(conn)
        cursor.execute("SELECT id, name, url, frequency, regex FROM sites")

        for row in cursor.fetchall():
            list_of_sites.append(CheckerConf.fromSQL(row))

        cursor.close()
    except (Exception, psycopg2.DatabaseError) as e:
        print(e)
    finally:
        if conn is not None:
            conn.close()  # Closing connection should close cursor as well.
    return list_of_sites
コード例 #3
0
def test_database_exists():
    conn, c = db.get_conn()
    if conn and c:
        print("Database Connected.")
コード例 #4
0
 def test_connection(self):
     self.assertIsNotNone(get_cursor(get_conn()))