Spaces:
Build error
Build error
Ronio Jerico Roque commited on
Commit ·
ff45211
1
Parent(s): 744e521
Refactor output generation in write_client_footprint to use safe_get for improved error handling and clarity
Browse files- classes/response_off.py +3 -3
- pages/output.py +14 -11
classes/response_off.py
CHANGED
|
@@ -39,8 +39,8 @@ class SeoOffPageAnalyst:
|
|
| 39 |
text = output["outputs"][0]["outputs"][0]["results"]["text"]["data"]["text"]
|
| 40 |
text = json.loads(text)
|
| 41 |
#st.write(text)
|
| 42 |
-
backlinks = text[0]
|
| 43 |
-
referring_domains = text[1]
|
| 44 |
|
| 45 |
return text
|
| 46 |
|
|
@@ -70,7 +70,7 @@ class SeoOffPageAnalyst:
|
|
| 70 |
upload_response(debug_info)
|
| 71 |
|
| 72 |
st.session_state['off_page_file_uploaded'] = ''
|
| 73 |
-
|
| 74 |
except Exception as e:
|
| 75 |
pass
|
| 76 |
st.session_state['analyzing'] = False
|
|
|
|
| 39 |
text = output["outputs"][0]["outputs"][0]["results"]["text"]["data"]["text"]
|
| 40 |
text = json.loads(text)
|
| 41 |
#st.write(text)
|
| 42 |
+
#backlinks = text[0]
|
| 43 |
+
#referring_domains = text[1]
|
| 44 |
|
| 45 |
return text
|
| 46 |
|
|
|
|
| 70 |
upload_response(debug_info)
|
| 71 |
|
| 72 |
st.session_state['off_page_file_uploaded'] = ''
|
| 73 |
+
|
| 74 |
except Exception as e:
|
| 75 |
pass
|
| 76 |
st.session_state['analyzing'] = False
|
pages/output.py
CHANGED
|
@@ -26,25 +26,28 @@ def write_client_footprint():
|
|
| 26 |
except TypeError:
|
| 27 |
socmed = None
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
markdown_table = "| Source/Channel | Current KPI |\n"
|
| 31 |
markdown_table += "|---|---|\n"
|
| 32 |
-
markdown_table += f"| Website Health Score | {result_web
|
| 33 |
-
markdown_table += f"| Organic Traffic to the Website | {
|
| 34 |
-
markdown_table += f"| Paid Traffic to the Website | {
|
| 35 |
-
markdown_table += f"| Referral Traffic to the Website | {
|
| 36 |
markdown_table += f"| Email Traffic to the Website | N/A |\n"
|
| 37 |
-
markdown_table += f"| Direct Traffic to the Website | {
|
| 38 |
markdown_table += f"| Social Traffic to the Website | N/A |\n"
|
| 39 |
markdown_table += f"| Display Traffic to the Website | N/A |\n"
|
| 40 |
markdown_table += f"| Email Database | N/A |\n"
|
| 41 |
-
markdown_table += f"| Facebook Followers | {
|
| 42 |
-
markdown_table += f"| Twitter Followers | {
|
| 43 |
-
markdown_table += f"| Instagram Followers | {
|
| 44 |
-
markdown_table += f"| Linkedin Followers | {
|
| 45 |
markdown_table += f"| Google My Business | N/A |\n"
|
| 46 |
-
markdown_table += f"| # of Keywords Ranking in Top 10 | {
|
| 47 |
-
markdown_table += f"| # of Keywords Ranking in Top 100 | {
|
| 48 |
|
| 49 |
return markdown_table
|
| 50 |
|
|
|
|
| 26 |
except TypeError:
|
| 27 |
socmed = None
|
| 28 |
|
| 29 |
+
def safe_get(data, key):
|
| 30 |
+
value = data.get(key)
|
| 31 |
+
return value if value else "N/A"
|
| 32 |
|
| 33 |
markdown_table = "| Source/Channel | Current KPI |\n"
|
| 34 |
markdown_table += "|---|---|\n"
|
| 35 |
+
markdown_table += f"| Website Health Score | {safe_get(result_web, 'website_overall_health_score')} |\n"
|
| 36 |
+
markdown_table += f"| Organic Traffic to the Website | {safe_get(seo, 'organic_traffic')} |\n"
|
| 37 |
+
markdown_table += f"| Paid Traffic to the Website | {safe_get(seo, 'paid_traffic')} |\n"
|
| 38 |
+
markdown_table += f"| Referral Traffic to the Website | {safe_get(seo, 'referral_traffic')} |\n"
|
| 39 |
markdown_table += f"| Email Traffic to the Website | N/A |\n"
|
| 40 |
+
markdown_table += f"| Direct Traffic to the Website | {safe_get(seo, 'direct_traffic')} |\n"
|
| 41 |
markdown_table += f"| Social Traffic to the Website | N/A |\n"
|
| 42 |
markdown_table += f"| Display Traffic to the Website | N/A |\n"
|
| 43 |
markdown_table += f"| Email Database | N/A |\n"
|
| 44 |
+
markdown_table += f"| Facebook Followers | {safe_get(socmed, 'facebook_followers')} |\n"
|
| 45 |
+
markdown_table += f"| Twitter Followers | {safe_get(socmed, 'twitter_followers')} |\n"
|
| 46 |
+
markdown_table += f"| Instagram Followers | {safe_get(socmed, 'instagram_followers')} |\n"
|
| 47 |
+
markdown_table += f"| Linkedin Followers | {safe_get(socmed, 'linkedin_followers')} |\n"
|
| 48 |
markdown_table += f"| Google My Business | N/A |\n"
|
| 49 |
+
markdown_table += f"| # of Keywords Ranking in Top 10 | {safe_get(seo, 'keyword_ranking_in_top_10')} |\n"
|
| 50 |
+
markdown_table += f"| # of Keywords Ranking in Top 100 | {safe_get(seo, 'keyword_ranking_in_top_100')} |\n"
|
| 51 |
|
| 52 |
return markdown_table
|
| 53 |
|