mirror of
https://github.com/Death916/deathclock.git
synced 2026-04-10 03:04:40 -07:00
wttr format change
This commit is contained in:
parent
ea4eaa3f34
commit
c5eef9de3a
5 changed files with 676 additions and 1506 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -10,3 +10,4 @@ chromedriver
|
|||
*.pyc
|
||||
.pyc
|
||||
*.jpg
|
||||
*.flox
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@ class State(rx.State):
|
|||
"""Starts the weather background task when the page loads."""
|
||||
rx.remove_local_storage("chakra-ui-color-mode") #trying to test themes remove after
|
||||
logging.info("Triggering background tasks: Weather")
|
||||
# *** FIX: Return a list containing the handler reference ***
|
||||
return [State.fetch_weather, State.fetch_sports]
|
||||
|
||||
# --- Sports Background Task ---
|
||||
|
|
@ -81,7 +80,6 @@ class State(rx.State):
|
|||
try:
|
||||
logging.info("Fetching sports scores...")
|
||||
# Fetch MLB and NBA scores
|
||||
#check if sports has updated in last 5 minutes if so skip
|
||||
if self.last_sports_update and (time.time() - self.last_sports_update) < 300:
|
||||
logging.info("Sports scores already updated within the last 5 minutes. Skipping fetch.")
|
||||
await asyncio.sleep(300)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ name = "deathclock"
|
|||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = [{ name = "Death916", email = "tavn1992@gmail.com" }]
|
||||
requires-python = ">=3.9,<3.11.4"
|
||||
requires-python = ">=3.12"
|
||||
dependencies = [
|
||||
"requests>=2.31.0,<3",
|
||||
"feedparser>=6.0.11,<7",
|
||||
|
|
|
|||
|
|
@ -22,15 +22,7 @@ class Weather(rx.Base):
|
|||
# e.g., /home/death916/code/python/deathclock/utils
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Construct the absolute path to the project root directory
|
||||
# This should be the parent directory of 'utils'
|
||||
# e.g., /home/death916/code/python/deathclock
|
||||
# --- FIX IS HERE ---
|
||||
project_root = os.path.dirname(script_dir)
|
||||
# -----------------
|
||||
|
||||
# Construct the absolute path to the 'assets' directory within the project root
|
||||
# e.g., /home/death916/code/python/deathclock/assets
|
||||
assets_dir = os.path.join(project_root, 'assets')
|
||||
|
||||
# Ensure the assets directory exists
|
||||
|
|
@ -40,8 +32,6 @@ class Weather(rx.Base):
|
|||
logging.info(f"Created assets directory: {assets_dir}")
|
||||
except OSError as e:
|
||||
logging.error(f"Failed to create assets directory {assets_dir}: {e}")
|
||||
# If directory creation fails, saving will also likely fail.
|
||||
# Consider raising an exception or returning None early.
|
||||
return assets_dir
|
||||
|
||||
def delete_old_screenshots(self, assets_dir: str):
|
||||
|
|
@ -60,20 +50,13 @@ class Weather(rx.Base):
|
|||
Returns the web path (e.g., '/weather.jpg') or None on failure.
|
||||
"""
|
||||
assets_dir = self._get_assets_dir()
|
||||
# If _get_assets_dir failed (e.g., couldn't create dir), it might be None or invalid.
|
||||
# Adding a check here could be useful, though currently it returns the path anyway.
|
||||
# if not assets_dir or not os.path.isdir(assets_dir):
|
||||
# logging.error("Assets directory path is invalid or missing.")
|
||||
# return None
|
||||
|
||||
# Full path to save the file, e.g., /home/death916/code/python/deathclock/assets/weather.jpg
|
||||
screenshot_path = os.path.join(assets_dir, WEATHER_FILENAME)
|
||||
|
||||
try:
|
||||
curl_command = [
|
||||
"curl",
|
||||
"-s", # Silent mode
|
||||
"v2.wttr.in/Sacramento.png?0T", # Fetch PNG, no border, no terminal escapes
|
||||
"v2.wttr.in/Sacramento.png?0u", # Fetch PNG, no border, no terminal escapes
|
||||
"-o",
|
||||
screenshot_path, # Save to the correct assets path
|
||||
]
|
||||
|
|
@ -85,8 +68,6 @@ class Weather(rx.Base):
|
|||
process = subprocess.run(curl_command, check=True, capture_output=True, text=True)
|
||||
logging.info(f"Curl command successful. Weather image saved to: {screenshot_path}") # Log correct save path
|
||||
|
||||
# *** Return the WEB PATH, which is relative to the assets dir ***
|
||||
# This part was already correct. Reflex serves the 'assets' folder at the root URL.
|
||||
return WEATHER_WEB_PATH # e.g., "/weather.jpg"
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue