poemsforaphrodite commited on
Commit
a678469
1 Parent(s): 9b49b5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -2
app.py CHANGED
@@ -578,11 +578,22 @@ def show_paginated_dataframe(report, rows_per_page=20):
578
  report['relevancy_score'] = report['relevancy_score'].apply(format_relevancy_score)
579
 
580
  def make_clickable(url):
581
- return f'<a href="{url}" target="_blank">{url}</a>'
 
 
582
 
583
  report['clickable_url'] = report['page'].apply(make_clickable)
584
 
585
- columns = ['clickable_url', 'query', 'impressions', 'clicks', 'ctr', 'position', 'relevancy_score']
 
 
 
 
 
 
 
 
 
586
  report = report[columns]
587
 
588
  sort_column = st.selectbox("Sort by:", columns[1:], index=columns[1:].index('impressions'))
@@ -625,6 +636,16 @@ def show_paginated_dataframe(report, rows_per_page=20):
625
 
626
  st.markdown(report.iloc[start_idx:end_idx].to_html(escape=False, index=False), unsafe_allow_html=True)
627
 
 
 
 
 
 
 
 
 
 
 
628
  # -------------
629
  # Main Streamlit App Function
630
  # -------------
 
578
  report['relevancy_score'] = report['relevancy_score'].apply(format_relevancy_score)
579
 
580
  def make_clickable(url):
581
+ # Truncate URL if it's longer than 50 characters
582
+ display_url = url[:47] + '...' if len(url) > 50 else url
583
+ return f'<a href="{url}" target="_blank">{display_url}</a>'
584
 
585
  report['clickable_url'] = report['page'].apply(make_clickable)
586
 
587
+ # Fetch page titles
588
+ report['page_title'] = report['page'].apply(get_page_title)
589
+
590
+ def make_clickable_title(row):
591
+ title = row['page_title'] if row['page_title'] else row['clickable_url']
592
+ return f'<a href="{row["page"]}" target="_blank">{title}</a>'
593
+
594
+ report['clickable_title'] = report.apply(make_clickable_title, axis=1)
595
+
596
+ columns = ['clickable_title', 'query', 'impressions', 'clicks', 'ctr', 'position', 'relevancy_score']
597
  report = report[columns]
598
 
599
  sort_column = st.selectbox("Sort by:", columns[1:], index=columns[1:].index('impressions'))
 
636
 
637
  st.markdown(report.iloc[start_idx:end_idx].to_html(escape=False, index=False), unsafe_allow_html=True)
638
 
639
+ # Add this function to fetch page titles
640
+ def get_page_title(url):
641
+ try:
642
+ response = requests.get(url, timeout=5)
643
+ soup = BeautifulSoup(response.text, 'html.parser')
644
+ title = soup.title.string if soup.title else None
645
+ return title.strip() if title else None
646
+ except:
647
+ return None
648
+
649
  # -------------
650
  # Main Streamlit App Function
651
  # -------------