Ronio Jerico Roque commited on
Commit
0ec76d2
·
1 Parent(s): b438494

Fix: Handle exceptions for session state retrieval in SEO analysis and update web analytics input placeholder

Browse files
classes/Seo.py CHANGED
@@ -196,6 +196,8 @@ class Seo:
196
  traffic_channels += f"\nReferral Traffic: {referral_traffic}"
197
  traffic_channels += df_traffic.to_csv(index=True)
198
 
 
 
199
  except KeyError:
200
  pass
201
 
@@ -207,6 +209,8 @@ class Seo:
207
  seo_keywords += f"\nKeyword Ranking Top 100: {keyword_ranking['Keyword_top_100']}\n\n"
208
 
209
  seo_keywords += df_seo.to_csv(index=True)
 
 
210
  except KeyError:
211
  pass
212
 
@@ -224,6 +228,8 @@ class Seo:
224
  traffic_aqcuisition += f"\nPaid Traffic: {ga4_paid_social}\nOrganic Traffic: {ga4_organic_traffic}\nDirect Traffic: {ga4_direct_traffic}\nReferral Traffic: {ga4_referral_traffic}"
225
  except KeyError:
226
  pass
 
 
227
 
228
  # OUTPUT FOR SEO ANALYST
229
  payload_txt_seo_keywords = {"question": seo_keywords}
 
196
  traffic_channels += f"\nReferral Traffic: {referral_traffic}"
197
  traffic_channels += df_traffic.to_csv(index=True)
198
 
199
+ except AttributeError:
200
+ pass
201
  except KeyError:
202
  pass
203
 
 
209
  seo_keywords += f"\nKeyword Ranking Top 100: {keyword_ranking['Keyword_top_100']}\n\n"
210
 
211
  seo_keywords += df_seo.to_csv(index=True)
212
+ except AttributeError:
213
+ pass
214
  except KeyError:
215
  pass
216
 
 
228
  traffic_aqcuisition += f"\nPaid Traffic: {ga4_paid_social}\nOrganic Traffic: {ga4_organic_traffic}\nDirect Traffic: {ga4_direct_traffic}\nReferral Traffic: {ga4_referral_traffic}"
229
  except KeyError:
230
  pass
231
+ except TypeError:
232
+ pass
233
 
234
  # OUTPUT FOR SEO ANALYST
235
  payload_txt_seo_keywords = {"question": seo_keywords}
classes/response_seo.py CHANGED
@@ -145,38 +145,44 @@ class Seo:
145
  st.write('')
146
  headers = {"Content-Type": "application/json", "x-api-key": f"{os.getenv('x-api-key')}"}
147
  payload = ""
 
148
  try:
 
149
  payload += self.fetch_data("SEO Keywords")
 
150
  except Exception as e:
151
  pass
152
  try:
 
153
  payload += self.fetch_data("Traffic Channels")
 
154
  except Exception as e:
155
  pass
156
  try:
 
157
  payload += self.fetch_data("Traffic Acquisition")
 
158
  except Exception as e:
159
  pass
160
  try:
 
161
  payload += self.fetch_data("Pages Indexed")
 
162
  except Exception as e:
163
  pass
164
  try:
 
165
  payload += self.fetch_data("Bounce Rate")
 
166
  except Exception as e:
167
  pass
168
  try:
169
  payload += self.fetch_backlinks("Backlinks")
 
170
  except Exception as e:
171
  pass
172
-
173
  try:
174
- session_bounce_rate = st.session_state['bounce_rate']
175
- session_page_index = st.session_state['pages_index']
176
- session_others = st.session_state['others']
177
- session_traffic_channels = st.session_state['df_traffic']
178
- session_traffic_aqcuisition = st.session_state['df_seo']
179
- if session_bounce_rate or session_page_index or session_others or session_traffic_aqcuisition or session_traffic_channels == 'uploaded':
180
  payload_txt = {"input_value": payload, "output_type": "text", "input_type": "chat"}
181
  payload_txt_model = self.request_model(payload_txt, headers)
182
  debug_info = {'data_field' : 'SEO Analyst', 'result': payload_txt_model}
@@ -187,6 +193,7 @@ class Seo:
187
  st.session_state['others'] = ''
188
  st.session_state['df_traffic'] = ''
189
  st.session_state['df_seo'] = ''
 
190
  except Exception as e:
191
  pass
192
  st.session_state['analyzing'] = False
 
145
  st.write('')
146
  headers = {"Content-Type": "application/json", "x-api-key": f"{os.getenv('x-api-key')}"}
147
  payload = ""
148
+ count = 0
149
  try:
150
+ session_traffic_aqcuisition = st.session_state['df_seo']
151
  payload += self.fetch_data("SEO Keywords")
152
+ count += 1
153
  except Exception as e:
154
  pass
155
  try:
156
+ session_traffic_channels = st.session_state['df_traffic']
157
  payload += self.fetch_data("Traffic Channels")
158
+ count += 1
159
  except Exception as e:
160
  pass
161
  try:
162
+ session_others = st.session_state['others']
163
  payload += self.fetch_data("Traffic Acquisition")
164
+ count += 1
165
  except Exception as e:
166
  pass
167
  try:
168
+ session_page_index = st.session_state['pages_index']
169
  payload += self.fetch_data("Pages Indexed")
170
+ count += 1
171
  except Exception as e:
172
  pass
173
  try:
174
+ session_bounce_rate = st.session_state['bounce_rate']
175
  payload += self.fetch_data("Bounce Rate")
176
+ count += 1
177
  except Exception as e:
178
  pass
179
  try:
180
  payload += self.fetch_backlinks("Backlinks")
181
+ count += 1
182
  except Exception as e:
183
  pass
 
184
  try:
185
+ if count >= 1:
 
 
 
 
 
186
  payload_txt = {"input_value": payload, "output_type": "text", "input_type": "chat"}
187
  payload_txt_model = self.request_model(payload_txt, headers)
188
  debug_info = {'data_field' : 'SEO Analyst', 'result': payload_txt_model}
 
193
  st.session_state['others'] = ''
194
  st.session_state['df_traffic'] = ''
195
  st.session_state['df_seo'] = ''
196
+ count = 0
197
  except Exception as e:
198
  pass
199
  st.session_state['analyzing'] = False
classes/website_and_tools.py CHANGED
@@ -277,7 +277,7 @@ class WebsiteAndTools:
277
  self.mobile_responsiveness = st.text_input("Mobile Responsiveness - GTMetrix:", placeholder='Enter Mobile Responsiveness')
278
  self.desktop_loading_speed = st.text_input("Desktop Loading Speed - GTMetrix:", placeholder='Enter Desktop Loading Speed')
279
  self.mobile_loading_speed = st.text_input("Mobile Loading Speed - GTMetrix:", placeholder='Enter Mobile Loading Speed')
280
- self.web_analytics = st.text_input("Web Analytics - BuiltWith:", placeholder='Enter Web Analytics')
281
  self.client_relations_management_system = st.text_input("Client Relations Management System - BuiltWith:", placeholder='Enter Client Relations Management System')
282
  self.lead_generation_mechanism = st.text_input("Lead Generation Mechanism - Business Context (Lead Generation & Lead Nurturing):", placeholder='Enter Lead Generation Mechanism')
283
 
 
277
  self.mobile_responsiveness = st.text_input("Mobile Responsiveness - GTMetrix:", placeholder='Enter Mobile Responsiveness')
278
  self.desktop_loading_speed = st.text_input("Desktop Loading Speed - GTMetrix:", placeholder='Enter Desktop Loading Speed')
279
  self.mobile_loading_speed = st.text_input("Mobile Loading Speed - GTMetrix:", placeholder='Enter Mobile Loading Speed')
280
+ self.web_analytics = st.text_input("Web Analytics - BuiltWith (GA4):", placeholder='Enter Web Analytics')
281
  self.client_relations_management_system = st.text_input("Client Relations Management System - BuiltWith:", placeholder='Enter Client Relations Management System')
282
  self.lead_generation_mechanism = st.text_input("Lead Generation Mechanism - Business Context (Lead Generation & Lead Nurturing):", placeholder='Enter Lead Generation Mechanism')
283