From 7d0a0cdfa656e98d029f963a02790ae0a6958933 Mon Sep 17 00:00:00 2001 From: death916 Date: Wed, 10 Dec 2025 02:10:30 -0800 Subject: [PATCH] change button to popover, init Radio_Control --- deathclock/deathclock.py | 5 ----- utils/news.py | 13 +++++++------ utils/radio.py | 27 +++++++++++++++++++-------- utils/scores.py | 15 ++++++--------- utils/weather.py | 8 ++------ 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/deathclock/deathclock.py b/deathclock/deathclock.py index e1da26d..a13fd9b 100755 --- a/deathclock/deathclock.py +++ b/deathclock/deathclock.py @@ -5,8 +5,6 @@ import asyncio import logging import time from datetime import datetime, timezone - -# --- Import typing for hints --- from typing import Any, Dict, List import reflex as rx @@ -16,7 +14,6 @@ from utils.radio import Radio from utils.scores import NBAScores, mlbScores, nflScores from utils.weather import Weather -# --- Constants --- WEATHER_IMAGE_PATH = "/weather.jpg" # Web path in assets folder WEATHER_FETCH_INTERVAL = 360 logging.basicConfig( @@ -87,8 +84,6 @@ class State(rx.State): State.cycle_news, ] - # --- Sports Background Task --- - @rx.event(background=True) async def fetch_sports(self): # Fetches sports scores periodically diff --git a/utils/news.py b/utils/news.py index 22c7965..7e3fe45 100755 --- a/utils/news.py +++ b/utils/news.py @@ -1,10 +1,11 @@ -import feedparser import asyncio -import aiofiles import random -from time import localtime, strftime import socket +from time import localtime, strftime + +import aiofiles import aiohttp +import feedparser def print_time(): @@ -13,11 +14,11 @@ def print_time(): class News: def __init__(self): - socket.setdefaulttimeout(10) # Set default timeout for socket operations + socket.setdefaulttimeout(10) async def _fetch_feed(self, session, feed): """Fetches and parses a single feed asynchronously.""" - max_entries = 10 # Maximum number of entries to fetch from each feed + max_entries = 10 try: # Add timeout to the request @@ -38,7 +39,7 @@ class News: # Limit the number of entries parsed for i, post in enumerate(d.entries): if i >= max_entries: - break # Stop parsing if we've reached the limit + break feed_entries.append( { diff --git a/utils/radio.py b/utils/radio.py index 839a489..13cfffa 100644 --- a/utils/radio.py +++ b/utils/radio.py @@ -3,20 +3,28 @@ import reflex as rx +CURRENT_STATION = "90.9 FM" +PLAYING = False + class Radio(rx.Base): def open_radio_button(self): return rx.button("Radio", on_click=self.open_radio_button) def radio_card(self): - radio_card = rx.card( - rx.vstack( - rx.heading("Radio"), - rx.text("Current Station"), - # rx.text("Volume"), - # rx.button("Play"), - # rx.button("Pause"), - # rx.button("Stop"), + radio_card = rx.popover.root( + rx.popover.trigger(rx.button("Radio")), + rx.popover.content( + rx.vstack( + rx.heading("Current Station"), + rx.text(CURRENT_STATION), + # rx.text("Volume"), + # rx.button("Play" + # on_click=Radio_Control.play_radio), + # ), + # rx.button("Pause"), + # rx.button("Stop"), + ), ), ) return radio_card @@ -25,3 +33,6 @@ class Radio(rx.Base): class Radio_Control: def __init__(self): pass + + def play_radio(self): + pass diff --git a/utils/scores.py b/utils/scores.py index 9e7cdfd..dea1a31 100755 --- a/utils/scores.py +++ b/utils/scores.py @@ -1,10 +1,10 @@ # /home/death916/code/python/deathclock/utils/scores.py -from nba_api.live.nba.endpoints import scoreboard -from datetime import datetime, timedelta -import statsapi -import reflex as rx import logging # Use logging for consistency +from datetime import datetime, timedelta +import reflex as rx +import statsapi +from nba_api.live.nba.endpoints import scoreboard logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" @@ -20,7 +20,6 @@ class NBAScores(rx.Base): board = scoreboard.ScoreBoard() data = board.get_dict() - # Check if we have a valid scoreboard response if "scoreboard" not in data: logging.warning("No NBA scoreboard data found in response") return [] @@ -74,7 +73,6 @@ class mlbScores(rx.Base): return [] for game in games: try: - # Ensure keys exist, provide defaults if necessary game_data = { "home_team": game.get("home_name", "N/A"), "home_score": game.get("home_score", "-"), @@ -84,12 +82,11 @@ class mlbScores(rx.Base): } scores_list.append(game_data) except KeyError as e: - # This block might be less necessary with .get() above logging.error( f"Error processing MLB game data: {e} for game: {game.get('game_id', 'N/A')}" ) - continue # Skip this game - return scores_list # RETURN THE LIST + continue + return scores_list class nflScores: diff --git a/utils/weather.py b/utils/weather.py index 18136c4..9d91214 100755 --- a/utils/weather.py +++ b/utils/weather.py @@ -6,7 +6,6 @@ import subprocess import reflex as rx -# Configure logging (optional but recommended) logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" ) @@ -18,12 +17,9 @@ WEATHER_WEB_PATH = f"/{WEATHER_FILENAME}" # This should be relative to the asse class Weather(rx.Base): - # No __init__ needed here for Pydantic compatibility - def _get_assets_dir(self) -> str: """Calculates and ensures the assets directory exists within the project.""" - # Get the directory where this script (weather.py) is located - # e.g., /home/death916/code/python/deathclock/utils + script_dir = os.path.dirname(os.path.abspath(__file__)) project_root = os.path.dirname(script_dir) @@ -75,7 +71,7 @@ class Weather(rx.Base): f"Curl command successful. Weather image saved to: {screenshot_path}" ) # Log correct save path - return WEATHER_WEB_PATH # e.g., "/weather.jpg" + return WEATHER_WEB_PATH except subprocess.CalledProcessError as e: logging.error(f"Curl command failed for path {screenshot_path}: {e}")