mirror of
https://github.com/Death916/deathclock.git
synced 2026-04-10 03:04:40 -07:00
change button to popover, init Radio_Control
This commit is contained in:
parent
b71911d7ab
commit
7d0a0cdfa6
5 changed files with 34 additions and 34 deletions
|
|
@ -5,8 +5,6 @@ import asyncio
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
# --- Import typing for hints ---
|
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
import reflex as rx
|
import reflex as rx
|
||||||
|
|
@ -16,7 +14,6 @@ from utils.radio import Radio
|
||||||
from utils.scores import NBAScores, mlbScores, nflScores
|
from utils.scores import NBAScores, mlbScores, nflScores
|
||||||
from utils.weather import Weather
|
from utils.weather import Weather
|
||||||
|
|
||||||
# --- Constants ---
|
|
||||||
WEATHER_IMAGE_PATH = "/weather.jpg" # Web path in assets folder
|
WEATHER_IMAGE_PATH = "/weather.jpg" # Web path in assets folder
|
||||||
WEATHER_FETCH_INTERVAL = 360
|
WEATHER_FETCH_INTERVAL = 360
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
|
|
@ -87,8 +84,6 @@ class State(rx.State):
|
||||||
State.cycle_news,
|
State.cycle_news,
|
||||||
]
|
]
|
||||||
|
|
||||||
# --- Sports Background Task ---
|
|
||||||
|
|
||||||
@rx.event(background=True)
|
@rx.event(background=True)
|
||||||
async def fetch_sports(self):
|
async def fetch_sports(self):
|
||||||
# Fetches sports scores periodically
|
# Fetches sports scores periodically
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import feedparser
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import aiofiles
|
|
||||||
import random
|
import random
|
||||||
from time import localtime, strftime
|
|
||||||
import socket
|
import socket
|
||||||
|
from time import localtime, strftime
|
||||||
|
|
||||||
|
import aiofiles
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
import feedparser
|
||||||
|
|
||||||
|
|
||||||
def print_time():
|
def print_time():
|
||||||
|
|
@ -13,11 +14,11 @@ def print_time():
|
||||||
|
|
||||||
class News:
|
class News:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
socket.setdefaulttimeout(10) # Set default timeout for socket operations
|
socket.setdefaulttimeout(10)
|
||||||
|
|
||||||
async def _fetch_feed(self, session, feed):
|
async def _fetch_feed(self, session, feed):
|
||||||
"""Fetches and parses a single feed asynchronously."""
|
"""Fetches and parses a single feed asynchronously."""
|
||||||
max_entries = 10 # Maximum number of entries to fetch from each feed
|
max_entries = 10
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Add timeout to the request
|
# Add timeout to the request
|
||||||
|
|
@ -38,7 +39,7 @@ class News:
|
||||||
# Limit the number of entries parsed
|
# Limit the number of entries parsed
|
||||||
for i, post in enumerate(d.entries):
|
for i, post in enumerate(d.entries):
|
||||||
if i >= max_entries:
|
if i >= max_entries:
|
||||||
break # Stop parsing if we've reached the limit
|
break
|
||||||
|
|
||||||
feed_entries.append(
|
feed_entries.append(
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,29 @@
|
||||||
|
|
||||||
import reflex as rx
|
import reflex as rx
|
||||||
|
|
||||||
|
CURRENT_STATION = "90.9 FM"
|
||||||
|
PLAYING = False
|
||||||
|
|
||||||
|
|
||||||
class Radio(rx.Base):
|
class Radio(rx.Base):
|
||||||
def open_radio_button(self):
|
def open_radio_button(self):
|
||||||
return rx.button("Radio", on_click=self.open_radio_button)
|
return rx.button("Radio", on_click=self.open_radio_button)
|
||||||
|
|
||||||
def radio_card(self):
|
def radio_card(self):
|
||||||
radio_card = rx.card(
|
radio_card = rx.popover.root(
|
||||||
|
rx.popover.trigger(rx.button("Radio")),
|
||||||
|
rx.popover.content(
|
||||||
rx.vstack(
|
rx.vstack(
|
||||||
rx.heading("Radio"),
|
rx.heading("Current Station"),
|
||||||
rx.text("Current Station"),
|
rx.text(CURRENT_STATION),
|
||||||
# rx.text("Volume"),
|
# rx.text("Volume"),
|
||||||
# rx.button("Play"),
|
# rx.button("Play"
|
||||||
|
# on_click=Radio_Control.play_radio),
|
||||||
|
# ),
|
||||||
# rx.button("Pause"),
|
# rx.button("Pause"),
|
||||||
# rx.button("Stop"),
|
# rx.button("Stop"),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
return radio_card
|
return radio_card
|
||||||
|
|
||||||
|
|
@ -25,3 +33,6 @@ class Radio(rx.Base):
|
||||||
class Radio_Control:
|
class Radio_Control:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def play_radio(self):
|
||||||
|
pass
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
# /home/death916/code/python/deathclock/utils/scores.py
|
# /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
|
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(
|
logging.basicConfig(
|
||||||
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
|
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
|
||||||
|
|
@ -20,7 +20,6 @@ class NBAScores(rx.Base):
|
||||||
board = scoreboard.ScoreBoard()
|
board = scoreboard.ScoreBoard()
|
||||||
data = board.get_dict()
|
data = board.get_dict()
|
||||||
|
|
||||||
# Check if we have a valid scoreboard response
|
|
||||||
if "scoreboard" not in data:
|
if "scoreboard" not in data:
|
||||||
logging.warning("No NBA scoreboard data found in response")
|
logging.warning("No NBA scoreboard data found in response")
|
||||||
return []
|
return []
|
||||||
|
|
@ -74,7 +73,6 @@ class mlbScores(rx.Base):
|
||||||
return []
|
return []
|
||||||
for game in games:
|
for game in games:
|
||||||
try:
|
try:
|
||||||
# Ensure keys exist, provide defaults if necessary
|
|
||||||
game_data = {
|
game_data = {
|
||||||
"home_team": game.get("home_name", "N/A"),
|
"home_team": game.get("home_name", "N/A"),
|
||||||
"home_score": game.get("home_score", "-"),
|
"home_score": game.get("home_score", "-"),
|
||||||
|
|
@ -84,12 +82,11 @@ class mlbScores(rx.Base):
|
||||||
}
|
}
|
||||||
scores_list.append(game_data)
|
scores_list.append(game_data)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
# This block might be less necessary with .get() above
|
|
||||||
logging.error(
|
logging.error(
|
||||||
f"Error processing MLB game data: {e} for game: {game.get('game_id', 'N/A')}"
|
f"Error processing MLB game data: {e} for game: {game.get('game_id', 'N/A')}"
|
||||||
)
|
)
|
||||||
continue # Skip this game
|
continue
|
||||||
return scores_list # RETURN THE LIST
|
return scores_list
|
||||||
|
|
||||||
|
|
||||||
class nflScores:
|
class nflScores:
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import subprocess
|
||||||
|
|
||||||
import reflex as rx
|
import reflex as rx
|
||||||
|
|
||||||
# Configure logging (optional but recommended)
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
|
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):
|
class Weather(rx.Base):
|
||||||
# No __init__ needed here for Pydantic compatibility
|
|
||||||
|
|
||||||
def _get_assets_dir(self) -> str:
|
def _get_assets_dir(self) -> str:
|
||||||
"""Calculates and ensures the assets directory exists within the project."""
|
"""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__))
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
project_root = os.path.dirname(script_dir)
|
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}"
|
f"Curl command successful. Weather image saved to: {screenshot_path}"
|
||||||
) # Log correct save path
|
) # Log correct save path
|
||||||
|
|
||||||
return WEATHER_WEB_PATH # e.g., "/weather.jpg"
|
return WEATHER_WEB_PATH
|
||||||
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
logging.error(f"Curl command failed for path {screenshot_path}: {e}")
|
logging.error(f"Curl command failed for path {screenshot_path}: {e}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue