11"""Query alert information from AeroAPI and present it to a frontend service"""
22import os
33from datetime import datetime
4- from typing import Dict , Any , Union
4+ from typing import Dict , Any , Tuple
55
66import json
77import requests
2626 "sqlite+pysqlite:////var/db/aeroapi_alerts/aeroapi_alerts.db" , echo = False , future = True
2727)
2828# Set journal_mode to WAL to enable reading and writing concurrently
29- with engine .connect () as conn :
30- conn .exec_driver_sql ("PRAGMA journal_mode=WAL" )
31- conn .commit ()
29+ with engine .connect () as conn_wal :
30+ conn_wal .exec_driver_sql ("PRAGMA journal_mode=WAL" )
31+ conn_wal .commit ()
3232
3333# Define tables and metadata to insert and create
3434metadata_obj = MetaData ()
@@ -86,7 +86,7 @@ def create_tables():
8686 raise e
8787
8888
89- def insert_into_table (data_to_insert : Dict [str , Union [ str , int , bool ] ], table : Table ) -> int :
89+ def insert_into_table (data_to_insert : Dict [str , Any ], table : Table ) -> int :
9090 """
9191 Insert object into the database based off of the table.
9292 Assumes data_to_insert has values for all the keys
@@ -107,7 +107,7 @@ def insert_into_table(data_to_insert: Dict[str, Union[str, int, bool]], table: T
107107
108108
109109@app .route ("/post" , methods = ["POST" ])
110- def handle_alert () -> ( Response , int ) :
110+ def handle_alert () -> Tuple [ Response , int ] :
111111 """
112112 Function to receive AeroAPI POST requests. Filters the request
113113 and puts the necessary data into the SQL database.
@@ -117,9 +117,9 @@ def handle_alert() -> (Response, int):
117117 r_title : str
118118 r_detail : str
119119 r_status : int
120- data : Dict [Any ] = request .json
120+ data : Dict [str , Any ] = request .json
121121 # Process data by getting things needed
122- processed_data : Dict [Any ]
122+ processed_data : Dict [str , Any ]
123123 try :
124124 processed_data = {
125125 "long_description" : data ["long_description" ],
@@ -169,7 +169,7 @@ def create_alert() -> Response:
169169 r_description : str = ''
170170 # Process json
171171 content_type = request .headers .get ("Content-Type" )
172- data : Dict [Any ]
172+ data : Dict [str , Any ]
173173
174174 if content_type != "application/json" :
175175 r_description = "Invalid content sent"
0 commit comments