Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -312,7 +312,60 @@ def make_nasa_soho_image_trigger():
|
|
| 312 |
#html_in+= make_nasa_soho_videos()
|
| 313 |
html_in+="</div>"
|
| 314 |
return html_in
|
| 315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
url_box=[]
|
| 317 |
in_year=f"{date1[0:4]}"
|
| 318 |
in_month=f"{date1[4:6]}"
|
|
@@ -364,6 +417,7 @@ def count_days(date1,date2):
|
|
| 364 |
|
| 365 |
|
| 366 |
def nasa_sdo_images(obj,size,date1,date2):
|
|
|
|
| 367 |
url_box=[]
|
| 368 |
html_in=f"<style>{css}</style><div class='img_box_soho'>"
|
| 369 |
print(date1 + " - " + date2)
|
|
|
|
| 312 |
#html_in+= make_nasa_soho_videos()
|
| 313 |
html_in+="</div>"
|
| 314 |
return html_in
|
| 315 |
+
from datetime import date, timedelta, datetime
|
| 316 |
+
|
| 317 |
+
def generate_sdo_urls(date1_str: str, date2_str: str) -> list[str]:
|
| 318 |
+
"""
|
| 319 |
+
Generates a list of SDO browse image URLs for all days
|
| 320 |
+
inclusive of date1_str and date2_str.
|
| 321 |
+
|
| 322 |
+
The URL format is assumed to be:
|
| 323 |
+
https://sdo.gsfc.nasa.gov/assets/img/browse/YYYY/MM/DD/
|
| 324 |
+
|
| 325 |
+
Args:
|
| 326 |
+
date1_str: Start date in "YYYYMMDD" format (e.g., "20230115").
|
| 327 |
+
date2_str: End date in "YYYYMMDD" format (e.g., "20230117").
|
| 328 |
+
|
| 329 |
+
Returns:
|
| 330 |
+
A list of URL strings.
|
| 331 |
+
Returns an empty list if date1_str > date2_str or if dates are invalid.
|
| 332 |
+
"""
|
| 333 |
+
url_box = []
|
| 334 |
+
base_url = "https://sdo.gsfc.nasa.gov/assets/img/browse"
|
| 335 |
+
|
| 336 |
+
try:
|
| 337 |
+
# Convert input strings to date objects
|
| 338 |
+
# datetime.strptime creates a datetime object, .date() gets just the date part
|
| 339 |
+
start_date = datetime.strptime(date1_str, "%Y%m%d").date()
|
| 340 |
+
end_date = datetime.strptime(date2_str, "%Y%m%d").date()
|
| 341 |
+
except ValueError:
|
| 342 |
+
print(f"Error: Invalid date format. Please use YYYYMMDD. Received: '{date1_str}', '{date2_str}'")
|
| 343 |
+
return [] # Return empty list for invalid date format
|
| 344 |
+
|
| 345 |
+
# Handle cases where start_date is after end_date
|
| 346 |
+
if start_date > end_date:
|
| 347 |
+
print(f"Warning: Start date ({date1_str}) is after end date ({date2_str}). Returning an empty list.")
|
| 348 |
+
return []
|
| 349 |
+
|
| 350 |
+
current_date = start_date
|
| 351 |
+
while current_date <= end_date:
|
| 352 |
+
# Format year, month, and day with leading zeros if necessary
|
| 353 |
+
# .year, .month, .day are integers
|
| 354 |
+
year_str = f"{current_date.year:04}" # Ensures YYYY format (though usually not needed for year)
|
| 355 |
+
month_str = f"{current_date.month:02}" # Ensures MM format (e.g., 1 -> 01)
|
| 356 |
+
day_str = f"{current_date.day:02}" # Ensures DD format (e.g., 5 -> 05)
|
| 357 |
+
|
| 358 |
+
# Construct the URL
|
| 359 |
+
out_url = f"{base_url}/{year_str}/{month_str}/{day_str}/"
|
| 360 |
+
url_box.append(out_url)
|
| 361 |
+
|
| 362 |
+
# Move to the next day
|
| 363 |
+
current_date += timedelta(days=1)
|
| 364 |
+
|
| 365 |
+
return url_box
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
def count_days_og(date1,date2):
|
| 369 |
url_box=[]
|
| 370 |
in_year=f"{date1[0:4]}"
|
| 371 |
in_month=f"{date1[4:6]}"
|
|
|
|
| 417 |
|
| 418 |
|
| 419 |
def nasa_sdo_images(obj,size,date1,date2):
|
| 420 |
+
print(generate_sdo_urls(date1,date2))
|
| 421 |
url_box=[]
|
| 422 |
html_in=f"<style>{css}</style><div class='img_box_soho'>"
|
| 423 |
print(date1 + " - " + date2)
|