Skip to content

Commit

Permalink
- update_hodo_page script fixes to restore favicon and added try/exce…
Browse files Browse the repository at this point in the history
…pt for zero length image list
  • Loading branch information
tjturnage committed Aug 19, 2024
1 parent d040049 commit 6b48fbf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ def get_sim(_yr, _mo, _dy, _hr, _mn, _dur) -> str:
object for use in scripts so don't need to be explicitly returned here.
"""
sa.make_simulation_times()
line1 = f'Start: {sa.event_start_str}Z ____ {sa.event_duration} minutes'
line1 = f'{sa.event_start_str}Z ____ {sa.event_duration} minutes'
return line1


Expand Down
4 changes: 3 additions & 1 deletion assets/hodographs.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<head>
<title>Hodographs</title>
<link rel="icon" type="image/x-icon" href="./favicon.ico">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootswatch/4.5.2/cyborg/bootstrap.min.css">
</head>
<body><h1>Graphics not available, check back later!</h1>
<body><br><br>
<h3>Graphics not available, check back later!</h3>
<script>
{interval_code}
</script>
Expand Down
29 changes: 18 additions & 11 deletions scripts/update_hodo_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<head>
<title>Hodographs</title>
<link rel="icon" type="image/x-icon" href="./favicon.ico">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootswatch/4.5.2/cyborg/bootstrap.min.css">
</head>
<body>"""

Expand Down Expand Up @@ -79,22 +80,28 @@ def make_valid_hodo_list(self) -> list:
valid_hodo_list = []
self.image_files = [f for f in os.listdir(HODOGRAPHS_DIR) if f.endswith('.png') or f.endswith('.jpg')]
self.image_files.sort()
self.first_image_path = self.image_files[0]
#print(self.image_files)
for filename in self.image_files:
file_time = datetime.strptime(filename[-19:-4], '%Y%m%d_%H%M%S').replace(tzinfo=pytz.UTC).timestamp()
if file_time < self.clock_time:
valid_hodo_list.append(filename)
valid_hodo_list.sort()
return valid_hodo_list
try:
self.first_image_path = self.image_files[0]
#print(self.image_files)
for filename in self.image_files:
file_time = datetime.strptime(filename[-19:-4], '%Y%m%d_%H%M%S').replace(tzinfo=pytz.UTC).timestamp()
if file_time < self.clock_time:
valid_hodo_list.append(filename)
valid_hodo_list.sort()
return valid_hodo_list
except IndexError as ie:
print(f'Could not find any hodographs in UpdateHodoHTML: {ie}')
self.initialize_hodo_page()
return []

def initialize_hodo_page(self) -> None:
"""
Initializes the hodographs.html page with a message that graphics are not available
"""
with open(HODOGRAPHS_PAGE, 'w', encoding='utf-8') as fout:
fout.write(HEAD_NOLIST)
fout.write('<h1>Graphics not available, check back later!</h1>\n')
fout.write('<br><br>\n')
fout.write('<h3>Graphics not available, check back later!</h3>\n')
fout.write(TAIL_NOLIST)

def update_hodo_page(self) -> None:
Expand Down Expand Up @@ -138,7 +145,7 @@ def update_hodographs_loop_page(self) -> None:
<html>
<head>
<title>Hodographs</title>
<link rel="icon" href="../favicon.ico" type="image/x-icon">
<link rel="icon" href="./favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootswatch/4.5.2/cyborg/bootstrap.min.css">
<style>
img {{ max-width: 90%; height: auto; }} /* Display images at 90% size */
Expand Down Expand Up @@ -186,7 +193,7 @@ def update_hodographs_loop_page(self) -> None:
<div class="slider-container mb-4">
<input type="range" min="0" max="{len(self.image_files) - 1}" value="0" class="slider" id="image-slider">
</div>
<div class="slider-text-container">Choose the half of the slider to used based on desired hodo type</div>
<div class="slider-text-container">Choose which half of the slider to use based on desired hodo type</div>
<script>
Expand Down

0 comments on commit 6b48fbf

Please sign in to comment.