-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb_data_retriever.py
More file actions
58 lines (50 loc) · 1.77 KB
/
web_data_retriever.py
File metadata and controls
58 lines (50 loc) · 1.77 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
import MySQLdb # or your preferred mysql library
class HealthDataRetriever:
def __init__(self):
self.config = {
'host': 'localhost',
'user': 'root',
'passwd': 'iamrahul',
'db': 'health_project'
}
def fetch_latest_vitals(self):
try:
# Connect to the database
db = MySQLdb.connect(**self.config)
cursor = db.cursor()
# Fetch the most recent record
query = """
SELECT bpm, spo2, glucose, hrv, status
FROM refined_health_data
ORDER BY id DESC
LIMIT 1
"""
cursor.execute(query)
data = cursor.fetchone()
# Close connection
db.close()
if data:
result = {
'bpm': data[0],
'spo2': data[1],
'glucose': data[2],
'hrv': data[3],
'status': data[4]
}
print("Latest Vitals Retrieved:")
print(f" BPM : {result['bpm']}")
print(f" SpO2 : {result['spo2']}%")
print(f" Glucose : {result['glucose']} mg/dL")
print(f" HRV : {result['hrv']} ms")
print(f" Status : {result['status']}")
return result
else:
print("No data found in refined_health_data table.")
return None
except Exception as e:
print(f"Database Error: {e}")
return None
# Example usage
if __name__ == "__main__":
retriever = HealthDataRetriever()
retriever.fetch_latest_vitals()