import json import os import streamlit as st from helper.data_field import get_analyst_response, data_field import time st.set_page_config(layout="centered") def write_client_footprint(): web = get_analyst_response("Website and Tools Analyst") result_web = {item["category"]: item["current_footprint"] for item in web} seo = get_analyst_response("SEO Analyst") seo = {item["category"]: item["current_footprint"] for item in seo} socmed = get_analyst_response("Social Media Analyst") socmed = {item["category"]: item["current_footprint"] for item in socmed} markdown_table = "| Source/Channel | Current KPI |\n" markdown_table += "|---|---|\n" markdown_table += f"| Website Health Score | {result_web['website_overall_health_score']} |\n" markdown_table += f"| Organic Traffic to the Website | {seo.get('organic_traffic', 'N/A')} |\n" markdown_table += f"| Paid Traffic to the Website | {seo.get('paid_traffic', 'N/A')} |\n" markdown_table += f"| Referral Traffic to the Website | {seo.get('referral_traffic', 'N/A')} |\n" markdown_table += f"| Email Traffic to the Website | N/A |\n" markdown_table += f"| Direct Traffic to the Website | {seo.get('direct_traffic', 'N/A')} |\n" markdown_table += f"| Social Traffic to the Website | N/A |\n" markdown_table += f"| Display Traffic to the Website | N/A |\n" markdown_table += f"| Email Database | N/A |\n" markdown_table += f"| Facebook Followers | {socmed.get('facebook_followers', 'N/A')} |\n" markdown_table += f"| Twitter Followers | {socmed.get('twitter_followers', 'N/A')} |\n" markdown_table += f"| Instagram Followers | {socmed.get('instagram_followers', 'N/A')} |\n" markdown_table += f"| Linkedin Followers | {socmed.get('linkedin_followers', 'N/A')} |\n" markdown_table += f"| Google My Business | N/A |\n" markdown_table += f"| # of Keywords Ranking in Top 10 | {seo.get('keyword_ranking_in_top_10', 'N/A')} |\n" markdown_table += f"| # of Keywords Ranking in Top 100 | {seo.get('keyword_ranking_in_top_100', 'N/A')} |\n" return markdown_table def write_table(website_and_tools_data): if website_and_tools_data: try: parsed_data = website_and_tools_data if isinstance(parsed_data, list): # Create Markdown table header markdown_table = "| | Current Footprint | Best of Breed Solution |\n" markdown_table += "|---|---|---|\n" # Loop through the list of dictionaries for item in parsed_data: # Use .get() for safety in case keys are missing category = item.get('category', 'N/A') current_footprint = item.get('current_footprint', 'N/A') best_of_breed = item.get('best_of_breed_solution', 'N/A') # Add a row to the Markdown table string # Replace underscores with spaces and apply title case to category category_formatted = category.replace('_', ' ').title() current_footprint_formatted = current_footprint.replace('_', ' ') best_of_breed_formatted = best_of_breed.replace('_', ' ') markdown_table += f"| {category_formatted} | {current_footprint_formatted} | {best_of_breed_formatted} |\n" # Display the complete Markdown table st.markdown(markdown_table) # Handle case if data is not a list (e.g., a single dictionary) elif isinstance(parsed_data, dict): st.write("Analysis Result (Summary):") # You might want to display dictionary data differently st.json(parsed_data) # Example: Display as JSON else: st.warning("data is not in the expected list format.") st.write(parsed_data) # Show the raw data except json.JSONDecodeError: st.error("Error: Could not parse the data as JSON.") st.text(website_and_tools_data) # Show the raw string data except AttributeError: st.error("Error: Could not find expected keys ('category', 'current_footprint', 'best_of_breed_solution') in the data.") st.write(parsed_data) # Show the data that caused the error except Exception as e: st.error(f"An unexpected error occurred while processing data: {e}") st.write(website_and_tools_data) # Show the raw data else: st.warning("No data retrieved for analysis.") # --- End: Loop and display data --- def seo_on_page_table(df_data): if df_data: try: parsed_data = df_data if isinstance(parsed_data, list): # Create Markdown table header markdown_table = "| Element | Description | Remarks |\n" markdown_table += "|---|---|---|\n" # Loop through the list of dictionaries for item in parsed_data: # Use .get() for safety in case keys are missing element = item.get('elements', 'N/A') description = item.get('description', 'Static information') remarks = item.get('remarks', 'N/A') # Add a row to the Markdown table string # Replace underscores with spaces and apply title case to element element_formatted = element.replace('_', ' ').title() description_formatted = description.replace('_', ' ') remarks_formatted = remarks.replace('_', ' ') markdown_table += f"| {element_formatted} | {description_formatted} | {remarks_formatted} |\n" # Display the complete Markdown table st.markdown(markdown_table) # Handle case if data is not a list (e.g., a single dictionary) elif isinstance(parsed_data, dict): st.write("Analysis Result (Summary):") # You might want to display dictionary data differently st.json(parsed_data) # Example: Display as JSON else: st.warning("data is not in the expected list format.") st.write(parsed_data) # Show the raw data except json.JSONDecodeError: st.error("Error: Could not parse the data as JSON.") st.text(df_data) # Show the raw string data except AttributeError: st.error("Error: Could not find expected keys ('category', 'current_footprint', 'best_of_breed_solution') in the data.") st.write(parsed_data) # Show the data that caused the error except Exception as e: st.error(f"An unexpected error occurred while processing data: {e}") st.write(df_data) # Show the raw data else: st.warning("No data retrieved for analysis.") # --- End: Loop and display data --- def display_outputs(): client_name = data_field("Client Name") client_website = data_field("Client Website") 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 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 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.""" st.markdown("# Digital Marketing Audit") st.markdown(f"for: **{client_name} ({client_website})**") st.write("") st.write("") st.write("") st.markdown("### DIGITAL FOOTPRINT OVERVIEW") st.markdown(f"{overview}") st.markdown("---") st.markdown("### Executive Summary") st.markdown(get_analyst_response("Executive Summary Analyst")) st.markdown("---") st.markdown("### CLIENT FOOTPRINT") st.markdown(write_client_footprint()) st.markdown( """