change button to popover, init Radio_Control

This commit is contained in:
death916 2025-12-10 02:10:30 -08:00
parent b71911d7ab
commit 7d0a0cdfa6
5 changed files with 34 additions and 34 deletions

View file

@ -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

View file

@ -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(
{

View file

@ -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

View file

@ -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:

View file

@ -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}")