-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
101 lines (76 loc) · 2.42 KB
/
Copy pathMain.py
File metadata and controls
101 lines (76 loc) · 2.42 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import mysql.connector
from mysql.connector import Error
from mysql.connector.pooling import MySQLConnectionPool
# Database configuration
db_config = {
"user": "root",
"password": "wlcm2T4",
"host": "localhost",
"database": "root",
"charset": "utf8mb4"
}
# Create a connection pool
connection_pool = MySQLConnectionPool(pool_name="mypool", pool_size=5, **db_config)
def get_coordinates_database():
"""
Retrieve coordinates from the database.
Returns:
tuple: Coordinates (x, y).
"""
try:
# Get a connection from the pool
connection = connection_pool.get_connection()
cursor = connection.cursor()
# Use parameterized query to prevent SQL injection
select_query = "SELECT x, y FROM coordinates WHERE id = %s;"
cursor.execute(select_query, (1,))
# Get the result
result = cursor.fetchone()
# Release resources
cursor.close()
connection.close()
return result
except Error as e:
return {"error": str(e)}
def get_geomagnetism_database():
"""
Retrieve geomagnetism information from the database.
Returns:
float: Geomagnetism information.
"""
try:
# Get a connection from the pool
connection = connection_pool.get_connection()
cursor = connection.cursor()
# Use parameterized query to prevent SQL injection
select_query = "SELECT direction FROM geomagnetism WHERE ID = %s;"
cursor.execute(select_query, (1,))
# Get the result
result = cursor.fetchone()
# Release resources
cursor.close()
connection.close()
return result
except Error as e:
return {"error": str(e)}
def get_route_information():
try:
# Get a connection from the pool
connection = connection_pool.get_connection()
cursor = connection.cursor()
# Use parameterized query to prevent SQL injection
select_query = "SELECT direction FROM geomagnetism WHERE ID = %s;"
cursor.execute(select_query, (1,))
# Get the result
result = cursor.fetchone()
# Release resources
cursor.close()
connection.close()
return result
except Error as e:
return {"error": str(e)}
def __main__():
print(get_coordinates_database())
print(get_geomagnetism_database())
if __name__ == "__main__":
__main__()