nakas commited on
Commit
28e8446
·
verified ·
1 Parent(s): f4c209e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -20
app.py CHANGED
@@ -6,7 +6,7 @@ import io
6
  import time
7
  import os
8
  import tempfile
9
- import base64
10
 
11
  # Montana cities with coordinates
12
  MONTANA_CITIES = {
@@ -88,6 +88,10 @@ def process_radar_images_for_html(city):
88
  timestamps.append(f"{time_text} (-{minutes_ago} min)")
89
 
90
  if image_urls:
 
 
 
 
91
  # Create HTML for browser-based animation
92
  html = f"""
93
  <div style="text-align: center; max-width: 100%;">
@@ -108,7 +112,7 @@ def process_radar_images_for_html(city):
108
  </div>
109
 
110
  <script>
111
- (function() {
112
  // Store all frame URLs and timestamps
113
  const frames = {json_urls};
114
  const timestamps = {json_timestamps};
@@ -126,44 +130,44 @@ def process_radar_images_for_html(city):
126
  const prevBtn = document.getElementById('prevBtn');
127
 
128
  // Function to update the displayed frame
129
- function updateFrame() {
130
  imgElement.src = frames[currentIndex];
131
  timestampElement.innerText = timestamps[currentIndex];
132
  frameCounter.innerText = currentIndex + 1;
133
- }
134
 
135
  // Function to play animation
136
- function playAnimation() {
137
- if (!isPlaying) {
138
  isPlaying = true;
139
- animationInterval = setInterval(() => {
140
  currentIndex = (currentIndex + 1) % frames.length;
141
  updateFrame();
142
- }, 700); // ~700ms delay between frames
143
- }
144
- }
145
 
146
  // Function to pause animation
147
- function pauseAnimation() {
148
- if (isPlaying) {
149
  isPlaying = false;
150
  clearInterval(animationInterval);
151
- }
152
- }
153
 
154
  // Function to show next frame
155
- function nextFrame() {
156
  pauseAnimation();
157
  currentIndex = (currentIndex + 1) % frames.length;
158
  updateFrame();
159
- }
160
 
161
  // Function to show previous frame
162
- function prevFrame() {
163
  pauseAnimation();
164
  currentIndex = (currentIndex - 1 + frames.length) % frames.length;
165
  updateFrame();
166
- }
167
 
168
  // Set up button event listeners
169
  playBtn.addEventListener('click', playAnimation);
@@ -173,9 +177,9 @@ def process_radar_images_for_html(city):
173
 
174
  // Start animation automatically
175
  playAnimation();
176
- })();
177
  </script>
178
- """.replace("{json_urls}", str(image_urls)).replace("{json_timestamps}", str(timestamps))
179
 
180
  return html
181
  else:
 
6
  import time
7
  import os
8
  import tempfile
9
+ import json
10
 
11
  # Montana cities with coordinates
12
  MONTANA_CITIES = {
 
88
  timestamps.append(f"{time_text} (-{minutes_ago} min)")
89
 
90
  if image_urls:
91
+ # Convert Python lists to JSON strings for JS
92
+ json_urls = json.dumps(image_urls)
93
+ json_timestamps = json.dumps(timestamps)
94
+
95
  # Create HTML for browser-based animation
96
  html = f"""
97
  <div style="text-align: center; max-width: 100%;">
 
112
  </div>
113
 
114
  <script>
115
+ (function() {{
116
  // Store all frame URLs and timestamps
117
  const frames = {json_urls};
118
  const timestamps = {json_timestamps};
 
130
  const prevBtn = document.getElementById('prevBtn');
131
 
132
  // Function to update the displayed frame
133
+ function updateFrame() {{
134
  imgElement.src = frames[currentIndex];
135
  timestampElement.innerText = timestamps[currentIndex];
136
  frameCounter.innerText = currentIndex + 1;
137
+ }}
138
 
139
  // Function to play animation
140
+ function playAnimation() {{
141
+ if (!isPlaying) {{
142
  isPlaying = true;
143
+ animationInterval = setInterval(() => {{
144
  currentIndex = (currentIndex + 1) % frames.length;
145
  updateFrame();
146
+ }}, 700); // ~700ms delay between frames
147
+ }}
148
+ }}
149
 
150
  // Function to pause animation
151
+ function pauseAnimation() {{
152
+ if (isPlaying) {{
153
  isPlaying = false;
154
  clearInterval(animationInterval);
155
+ }}
156
+ }}
157
 
158
  // Function to show next frame
159
+ function nextFrame() {{
160
  pauseAnimation();
161
  currentIndex = (currentIndex + 1) % frames.length;
162
  updateFrame();
163
+ }}
164
 
165
  // Function to show previous frame
166
+ function prevFrame() {{
167
  pauseAnimation();
168
  currentIndex = (currentIndex - 1 + frames.length) % frames.length;
169
  updateFrame();
170
+ }}
171
 
172
  // Set up button event listeners
173
  playBtn.addEventListener('click', playAnimation);
 
177
 
178
  // Start animation automatically
179
  playAnimation();
180
+ }})();
181
  </script>
182
+ """
183
 
184
  return html
185
  else: