-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (40 loc) · 1 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import eqlpy.eql_types
import psycopg2
import eqlpy
def fetch_data_from_db():
# Database connection parameters
host = "localhost"
port = 5442
database = "postgres"
user = "postgres"
password = "postgres"
try:
# Connect to PostgreSQL database
connection = psycopg2.connect(
host=host,
port=port,
database=database,
user=user,
password=password
)
cursor = connection.cursor()
# Execute the query
query = "SELECT * FROM pycon_cta;"
cursor.execute(query)
# Fetch and print all results
results = cursor.fetchall()
for row in results:
if row[1]["k"] == "ct":
print (f"Ciphertext: {row[1]['c']}")
else:
plaintext = eqlpy.eql_types.EqlText.from_parsed_json(row[1])
print(f"Plaintext: {plaintext}")
except Exception as error:
print(f"An error occurred: {error}")
finally:
if cursor:
cursor.close()
if connection:
connection.close()
if __name__ == "__main__":
fetch_data_from_db()