mirror of
https://github.com/Death916/deathclock.git
synced 2026-04-10 03:04:40 -07:00
formatting
This commit is contained in:
parent
fc96dca01f
commit
4b43284529
2 changed files with 35 additions and 27 deletions
|
|
@ -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,7 +76,7 @@ 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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue