summaryrefslogtreecommitdiff
path: root/src/db_handler.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/db_handler.py')
-rw-r--r--src/db_handler.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/db_handler.py b/src/db_handler.py
index 576612a..7766da1 100644
--- a/src/db_handler.py
+++ b/src/db_handler.py
@@ -33,8 +33,24 @@ def get_top(column: str) -> (list[dict], list[str]):
GROUP BY {column}
ORDER BY COUNT({column}) DESC
LIMIT 20;
- """).format(column=psycopg.sql.Identifier(column),))
+ """).format(column=psycopg.sql.Identifier(column), ))
top_usernames = cur.fetchall()
col_names = [desc[0] for desc in cur.description]
return top_usernames, col_names
+
+
+def get_password_of_the_month() -> str:
+ with psycopg.connect(**db_con_params, row_factory=psycopg.rows.dict_row) as conn:
+ with conn.cursor() as cur:
+ cur.execute("""
+SELECT password
+FROM login_attempt
+WHERE timestamp BETWEEN current_timestamp - interval '1 month' AND timestamp
+GROUP BY password
+ORDER BY COUNT(password) DESC
+LIMIT 1;
+ """)
+
+ password = cur.fetchone()['password']
+ return password