diff --git a/app/site/data.py b/app/site/data.py index cf9dfb5..7862a01 100644 --- a/app/site/data.py +++ b/app/site/data.py @@ -186,6 +186,7 @@ def get_main_headline_df(): 'title': Headline.processed, 'agency': Agency.name, 'bias': Agency._bias, # noqa prot attr + 'appearance': Article.first_accessed, 'first_accessed': Headline.first_accessed, 'last_accessed': Headline.last_accessed, 'position': Headline.position, @@ -213,6 +214,9 @@ def get_main_headline_df(): if len(df) == 0: sys.exit("No headlines found. Exiting.") + df['appearance'] = df['appearance'].dt.tz_localize('utc').dt.tz_convert('US/Eastern') + now = pd.Timestamp.now(tz='US/Eastern') + df['howlong'] = (now - df['appearance']).dt.total_seconds() df['first_accessed'] = df['first_accessed'].dt.tz_localize('utc').dt.tz_convert('US/Eastern') df['last_accessed'] = df['last_accessed'].dt.tz_localize('utc').dt.tz_convert('US/Eastern') roundcol = ['vader_compound', 'afinn', 'topic_score'] diff --git a/app/site/page_headlines.py b/app/site/page_headlines.py index ac66483..250370c 100644 --- a/app/site/page_headlines.py +++ b/app/site/page_headlines.py @@ -104,8 +104,10 @@ def cluster_and_summarize(self, df): clusters_list = [{'cluster': key, 'data': group.to_dict(orient='records')} for key, group in grouped] for cluster in clusters_list: cluster['coverage'] = round(len(cluster['data']) / len(Scrapers) * 100, 2) + cluster['first'] = max(cluster['data'], key=lambda x: x['howlong'])['howlong'] - clusters_list.sort(key=lambda x: len(x['data']), reverse=True) + # clusters_list.sort(key=lambda x: len(x['data']), reverse=True) + clusters_list.sort(key=lambda x: x['first']) self.make_agency_lists(clusters_list) self.context['clusters'] = clusters_list @@ -114,6 +116,12 @@ def make_agency_lists(self, clusters_list): for cluster in clusters_list: cluster['data'].sort(key=lambda x: x['agency']) hrefs = [f"
{len(cluster['data'])} headlines / {cluster['coverage']}% coverage
"] + # if cluster['first'] / 60 < 4 * 60: + minutes = cluster['first'] // 60 + if minutes < 90: + hrefs[-1] = hrefs[-1] + f'First broken {int(cluster["first"] // 60 // 60)} hours ago
' last_bias = -3 for a in sorted(cluster['data'], key=lambda x: x['bias']): if a['bias'] != last_bias: