mirror of
https://github.com/anatolykopyl/DINS-test-assignment.git
synced 2026-03-26 12:55:05 +00:00
Added a check for MySQL table existance
This commit is contained in:
5
main.py
5
main.py
@@ -16,7 +16,7 @@ with open('raw_data2.csv', 'rt', encoding="UTF-8") as csvfile:
|
|||||||
|
|
||||||
name = row[1] + "*" + row[2] # combining api_name and http_method into a pair name
|
name = row[1] + "*" + row[2] # combining api_name and http_method into a pair name
|
||||||
|
|
||||||
if 'start_time' not in locals():
|
if 'start_time2' not in locals():
|
||||||
start_time = timestamp
|
start_time = timestamp
|
||||||
start_time = int(min(start_time, timestamp)) # earliest request
|
start_time = int(min(start_time, timestamp)) # earliest request
|
||||||
if 'end_time' not in locals():
|
if 'end_time' not in locals():
|
||||||
@@ -45,6 +45,9 @@ is_anomaly(result)
|
|||||||
try:
|
try:
|
||||||
connection = MySQLdb.connect(host="127.0.0.1", user="user1", passwd="testserver", db="mydb")
|
connection = MySQLdb.connect(host="127.0.0.1", user="user1", passwd="testserver", db="mydb")
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
cursor.execute("SHOW TABLES LIKE 'result'")
|
||||||
|
if not cursor.fetchone(): # check if table already exists
|
||||||
cursor.execute("CREATE TABLE result ( timeframe_start TIMESTAMP, api_name TEXT, http_method TEXT, \
|
cursor.execute("CREATE TABLE result ( timeframe_start TIMESTAMP, api_name TEXT, http_method TEXT, \
|
||||||
count_http_code_5xx INT, is_anomaly TINYINT(1) )")
|
count_http_code_5xx INT, is_anomaly TINYINT(1) )")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user