Romeo David commited on
Commit
04eb7e1
·
1 Parent(s): 4a29236

added helper function to get analyst response from database

Browse files
Files changed (1) hide show
  1. helper/data_field.py +21 -1
helper/data_field.py CHANGED
@@ -8,4 +8,24 @@ def data_field(data_src):
8
  x = mycol.find_one({"data_field": data_src})
9
  x = x["result"]["question"]
10
  #st.write(x)
11
- return x
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  x = mycol.find_one({"data_field": data_src})
9
  x = x["result"]["question"]
10
  #st.write(x)
11
+ return x
12
+
13
+ def get_analyst_response(data_src):
14
+ try:
15
+ mongodb_uri = os.getenv("MONGODB_URI")
16
+ myclient = MongoClient(mongodb_uri)
17
+ mydb = myclient.get_database()
18
+ mycol = mydb["df_response"]
19
+ x = mycol.find_one({"data_field": data_src},
20
+ sort=[('timestamp', -1)])
21
+ if x and "result" in x:
22
+ return x["result"]
23
+ else:
24
+ print(f"No matching document or 'result' field found for data_src: {data_src} in df_response")
25
+ return None # Return None if no doc or 'result' field found
26
+ finally:
27
+ if myclient:
28
+ myclient.close()
29
+
30
+ #
31
+