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
|
|
@ -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:
|
||||
|
|
@ -95,4 +76,4 @@ class Weather(rx.Base):
|
|||
return None
|
||||
except Exception as e:
|
||||
logging.error(f"An unexpected error occurred saving to {screenshot_path}: {e}")
|
||||
return None
|
||||
return None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue