website and tools integration

#2
by notjulietxd - opened
Files changed (2) hide show
  1. helper/data_field.py +21 -1
  2. pages/output.py +63 -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
+
pages/output.py CHANGED
@@ -1,13 +1,19 @@
 
1
  import os
2
  import streamlit as st
3
-
4
  import time
5
 
 
 
6
  def display_outputs():
7
  client_name = "RMX Creatives"
8
  overview = f"""**{client_name}** is a financial services company based in Auckland, New Zealand, specializing in providing quick and flexible loan solutions for businesses and individuals. Represented by Paul Stone, LoansOne has enlisted ShoreMarketing to perform a deep dive into their digital footprint to have a view of the holistic status of their digital properties and determine how each property can play part in implementing a stronger digital marketing plan.\n
9
  The Digital Marketing Footprint consists of deep-dive research by ShoreMarketing specialists to help the business leaders of LoansOne understand the effectiveness of their existing digital initiatives with the view of giving them an insight to developing a strategy and effectively allocating business resources to digital properties that will give them the best results.\n
10
  This document represents the results of our audit of LoansOne’s digital marketing and management practices. Our audit covered reviews of key digital areas: Website and Tools, PPC/SEM, SEO, Social Media, and Market Places."""
 
 
 
11
 
12
  # (off_page_thread)
13
  # (on_page_thread)
@@ -24,6 +30,62 @@ This document represents the results of our audit of LoansOne’s digital market
24
  st.markdown(f"""In today’s digital age, scaling a business is simply impossible without a website. Websites primarily serve as the center for all online conversions, which makes it equally important to guarantee that all pages are optimised to educate all traffic about the brand and ultimately to usher them into conversion. \n
25
  In line with this, we have looked into the technology used by **{client_name}** as well as the different digital channels currently in place to see how they are structured and how they are performing.""")
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  if st.button("Back to Dashboard"):
29
  st.switch_page("pages/home.py")
 
1
+ import json
2
  import os
3
  import streamlit as st
4
+ from helper.data_field import get_analyst_response
5
  import time
6
 
7
+ st.set_page_config(layout="centered") # <--- Add this line
8
+
9
  def display_outputs():
10
  client_name = "RMX Creatives"
11
  overview = f"""**{client_name}** is a financial services company based in Auckland, New Zealand, specializing in providing quick and flexible loan solutions for businesses and individuals. Represented by Paul Stone, LoansOne has enlisted ShoreMarketing to perform a deep dive into their digital footprint to have a view of the holistic status of their digital properties and determine how each property can play part in implementing a stronger digital marketing plan.\n
12
  The Digital Marketing Footprint consists of deep-dive research by ShoreMarketing specialists to help the business leaders of LoansOne understand the effectiveness of their existing digital initiatives with the view of giving them an insight to developing a strategy and effectively allocating business resources to digital properties that will give them the best results.\n
13
  This document represents the results of our audit of LoansOne’s digital marketing and management practices. Our audit covered reviews of key digital areas: Website and Tools, PPC/SEM, SEO, Social Media, and Market Places."""
14
+ website_and_tools_data = get_analyst_response("Website and Tools Analyst")
15
+ # seo = data_field("SEO")
16
+ # social_media = data_field("Social Media")
17
 
18
  # (off_page_thread)
19
  # (on_page_thread)
 
30
  st.markdown(f"""In today’s digital age, scaling a business is simply impossible without a website. Websites primarily serve as the center for all online conversions, which makes it equally important to guarantee that all pages are optimised to educate all traffic about the brand and ultimately to usher them into conversion. \n
31
  In line with this, we have looked into the technology used by **{client_name}** as well as the different digital channels currently in place to see how they are structured and how they are performing.""")
32
 
33
+ # --- Start: Loop and display data as Markdown table ---
34
+ if website_and_tools_data:
35
+ try:
36
+ # If get_analyst_response returns a JSON string, parse it:
37
+ # parsed_data = json.loads(website_and_tools_data)
38
+
39
+ # If get_analyst_response returns a Python list/dict directly:
40
+ parsed_data = website_and_tools_data
41
+
42
+ # Check if the parsed data is a list (expected format for a table)
43
+ if isinstance(parsed_data, list):
44
+ # Create Markdown table header
45
+ markdown_table = "| Category | Current Footprint | Best of Breed Solution |\n"
46
+ markdown_table += "|---|---|---|\n"
47
+
48
+ # Loop through the list of dictionaries
49
+ for item in parsed_data:
50
+ # Use .get() for safety in case keys are missing
51
+ category = item.get('category', 'N/A')
52
+ current_footprint = item.get('current_footprint', 'N/A')
53
+ best_of_breed = item.get('best_of_breed_solution', 'N/A')
54
+
55
+ # Add a row to the Markdown table string
56
+ # Replace underscores with spaces and apply title case to category
57
+ category_formatted = category.replace('_', ' ').title()
58
+ current_footprint_formatted = current_footprint.replace('_', ' ')
59
+ best_of_breed_formatted = best_of_breed.replace('_', ' ')
60
+
61
+ markdown_table += f"| {category_formatted} | {current_footprint_formatted} | {best_of_breed_formatted} |\n"
62
+
63
+
64
+ # Display the complete Markdown table
65
+ st.markdown(markdown_table)
66
+
67
+ # Handle case if data is not a list (e.g., a single dictionary)
68
+ elif isinstance(parsed_data, dict):
69
+ st.write("Website and Tools Analysis Result (Summary):")
70
+ # You might want to display dictionary data differently
71
+ st.json(parsed_data) # Example: Display as JSON
72
+ else:
73
+ st.warning("Website and Tools data is not in the expected list format.")
74
+ st.write(parsed_data) # Show the raw data
75
+
76
+ except json.JSONDecodeError:
77
+ st.error("Error: Could not parse the Website and Tools data as JSON.")
78
+ st.text(website_and_tools_data) # Show the raw string data
79
+ except AttributeError:
80
+ st.error("Error: Could not find expected keys ('category', 'current_footprint', 'best_of_breed_solution') in the data.")
81
+ st.write(parsed_data) # Show the data that caused the error
82
+ except Exception as e:
83
+ st.error(f"An unexpected error occurred while processing Website and Tools data: {e}")
84
+ st.write(website_and_tools_data) # Show the raw data
85
+ else:
86
+ st.warning("No data retrieved for Website and Tools analysis.")
87
+ # --- End: Loop and display data ---
88
+
89
 
90
  if st.button("Back to Dashboard"):
91
  st.switch_page("pages/home.py")