-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_query_database.py
More file actions
34 lines (26 loc) · 1.14 KB
/
02_query_database.py
File metadata and controls
34 lines (26 loc) · 1.14 KB
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
import sqlite3
import json
def search_endpoint(query):
"""Search for API endpoints containing the query string."""
sqliteDB = "api_schema4_leostream.db"
conn = sqlite3.connect(sqliteDB)
cursor = conn.cursor()
cursor.execute("SELECT path, method, description, request_body, responses FROM api_endpoints WHERE path LIKE ?", (f"%{query}%",))
results = cursor.fetchall()
conn.close()
return results
if __name__ == "__main__":
query = input("> Enter an API path keyword to search: ")
endpoints = search_endpoint(query)
if endpoints:
for path, method, description, request_body, responses in endpoints:
print(f"\n - Endpoint: {path}\nMethod: {method}\nDescription: {description}")
# Pretty-print request body
if request_body and request_body != "None":
print("\n📥 Request Body Schema:")
print(json.dumps(json.loads(request_body), indent=2))
# Pretty-print responses
print("\n> Response Codes:")
print(json.dumps(json.loads(responses), indent=2))
else:
print(">>> No matching endpoints found.")