From 4b4328452916d2cf3cc9fad65d7bd2d9257895d5 Mon Sep 17 00:00:00 2001 From: Death916 Date: Wed, 5 Feb 2025 04:10:08 -0800 Subject: [PATCH] formatting --- deathclock/app.py | 52 ++++++++++++++++++++++++---------------------- deathclock/news.py | 10 +++++++-- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/deathclock/app.py b/deathclock/app.py index 6ab363f..b29b7fe 100644 --- a/deathclock/app.py +++ b/deathclock/app.py @@ -54,10 +54,12 @@ def update_time(n): ) def update_weather(n): try: + print("UPDATING WEATHER...") + print_time() weather_obj.get_weather_screenshot() return html.Div([ html.H2("Sacramento Weather"), - html.Img(src=app.get_asset_url('sacramento_weather_map.png'), + html.Img(src=app.get_asset_url('sacramento_weather_map.png'+ f"?v={datetime.datetime.now().timestamp()}"), style={'maxWidth': '500px'}) ]) except Exception as e: @@ -74,34 +76,34 @@ def update_news(n): current_time = datetime.datetime.now() try: - if _initial_run or (current_time - _last_news_update).total_seconds() >= 400: - print("Fetching fresh news due to timer...") - headlines_dict = news_obj.get_news() - if not isinstance(headlines_dict, dict): - raise ValueError("News update error: Invalid data format") - if not headlines_dict: - raise ValueError("No news fetched") + + print("Fetching fresh news due to timer...") + headlines_dict = news_obj.get_news() + if not isinstance(headlines_dict, dict): + raise ValueError("News update error: Invalid data format") + if not headlines_dict: + raise ValueError("No news fetched") - combined_text = " | ".join(headlines_dict.keys()) - text_px = len(combined_text) * 8 # Approx 8px per character - scroll_speed = 75 # px per second - duration = text_px / scroll_speed # seconds to scroll across + combined_text = " | ".join(headlines_dict.keys()) + text_px = len(combined_text) * 8 # Approx 8px per character + scroll_speed = 75 # px per second + duration = text_px / scroll_speed # seconds to scroll across - # Enforce a floor duration so it's not too quick for short text - if duration < 20: - duration = 20 + # Enforce a floor duration so it's not too quick for short text + if duration < 20: + duration = 20 - ticker_style = {"animationDuration": f"{duration}s"} - - combined_items = " | ".join([f"{headline}" for headline in headlines_dict.keys()]) + ticker_style = {"animationDuration": f"{duration}s"} + + combined_items = " | ".join([f"{headline}" for headline in headlines_dict.keys()]) - _cached_news = html.Div( - html.Span(combined_items, className="news-item", style=ticker_style), - className='ticker' - ) - _last_news_update = current_time - _initial_run = False - return _cached_news + _cached_news = html.Div( + html.Span(combined_items, className="news-item", style=ticker_style), + className='ticker' + ) + _last_news_update = current_time + _initial_run = False + return _cached_news except Exception as e: print(f"News update error: {str(e)}") diff --git a/deathclock/news.py b/deathclock/news.py index cb15c9f..3bc7e66 100644 --- a/deathclock/news.py +++ b/deathclock/news.py @@ -1,5 +1,6 @@ import feedparser from time import localtime, strftime +import random def print_time(): print(strftime("%B %d, %I:%M %p", localtime())) @@ -12,7 +13,7 @@ class News: print_time() feeds = [] self._news_dict = {} # Reset dict each time - + self._news_dict_length = 0 # Load RSS feed list with open("feeds.txt", "r") as f: feeds = [line.strip() for line in f] @@ -20,7 +21,12 @@ class News: # Get latest news from each feed for feed in feeds: d = feedparser.parse(feed) - for post in d.entries[:20]: # Limit to 3 entries per feed + #randomly select 20 news items + random.shuffle(d.entries) + #its getting all posts from first feed because there is more than 20 + + + for post in d.entries[:20]: # Limit to 20 entries per feed if self._news_dict_length >= 20: # Max 20 total entries return self._news_dict