Wajahat698 commited on
Commit
9fb803d
·
verified ·
1 Parent(s): bbf4602

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -169,12 +169,19 @@ def fetch_trustbuilders(user_id, keyword=None, brand=None, bucket=None):
169
  try:
170
  trustbuilders = db.child("users").child(user_id).child("TrustBuilder").get().val()
171
  if trustbuilders:
172
- filtered_trustbuilders = {
173
- k: v for k, v in trustbuilders.items()
174
- if (not keyword or keyword.lower() in v.get("message", "").lower())
175
- and (not brand or brand.lower() in v.get("brand", "").lower())
176
- and (not bucket or bucket == v.get("bucket", ""))
177
- }
 
 
 
 
 
 
 
178
  return filtered_trustbuilders
179
  return {}
180
  except Exception as e:
@@ -522,11 +529,12 @@ def save_content(user_id, brand, trust_builder_text, trust_bucket=None):
522
  "message": trust_builder_text,
523
  "bucket": trust_bucket
524
  }
 
 
525
  db.child("users").child(user_id).child("TrustBuilder").child(trustbuilder_id).set(data)
526
  st.success(f"TrustBuilder saved to {trust_bucket} bucket.")
527
  except Exception as e:
528
  st.error(f"Error saving TrustBuilder: {e}")
529
-
530
  def ai_allocate_trust_bucket(trust_builder_text):
531
  # Implement your AI allocation logic here
532
  return "Stability"
 
169
  try:
170
  trustbuilders = db.child("users").child(user_id).child("TrustBuilder").get().val()
171
  if trustbuilders:
172
+ filtered_trustbuilders = {}
173
+ for k, v in trustbuilders.items():
174
+ message = v.get("message", "").lower()
175
+ brand_field = v.get("brand", "").lower()
176
+ bucket_field = v.get("bucket", "")
177
+
178
+ if keyword and keyword.lower() not in message:
179
+ continue
180
+ if brand and brand.lower() not in brand_field:
181
+ continue
182
+ if bucket and bucket != bucket_field:
183
+ continue
184
+ filtered_trustbuilders[k] = v
185
  return filtered_trustbuilders
186
  return {}
187
  except Exception as e:
 
529
  "message": trust_builder_text,
530
  "bucket": trust_bucket
531
  }
532
+ # Output the data being saved
533
+ st.write("Saving TrustBuilder with data:", data)
534
  db.child("users").child(user_id).child("TrustBuilder").child(trustbuilder_id).set(data)
535
  st.success(f"TrustBuilder saved to {trust_bucket} bucket.")
536
  except Exception as e:
537
  st.error(f"Error saving TrustBuilder: {e}")
 
538
  def ai_allocate_trust_bucket(trust_builder_text):
539
  # Implement your AI allocation logic here
540
  return "Stability"