'
return html_out, None
return None,None
def make_tree(url1="",url2="",url3="",url4="",url5="",url6="",url7="",url8=""):
link_box=[]
html_out=""
get_url=f'{main_directory}{url1}{url2}{url3}{url4}{url5}{url6}{url7}{url8}'
print(f'######### :: {get_url}')
if not get_url.endswith('.json'):
feed1 = requests.get(get_url)
spl = feed1.text.split("href=")
for line in spl:
spl2 = line.split(">")[0]
#print(spl2)
if spl2.endswith('/"') or spl2.endswith('.json"') or spl2.endswith('.png"') or spl2.endswith('.gif"') or spl2.endswith('.jpg"'):
fin=line.split(">")[0].strip('""')
link_box.append(fin)
#html_out=html_out+html.replace("PAGE_LINK",fin)
return gr.update(choices=[l for l in link_box],interactive=True)
else:
return None
def get_images():
html_out=f"
"
get_url=f'{main_directory}images/geospace/'
feed1 = requests.get(get_url)
spl = feed1.text.split("href=")
for line in spl:
spl2 = line.split(">")[0].strip('""')
if spl2.endswith(".png") or spl2.endswith(".gif") or spl2.endswith(".jpg"):
#print(spl2)
html_out+=f'
'
else:
print(spl2)
get_url2=f'{main_directory}images/'
feed2 = requests.get(get_url2)
spl = feed2.text.split("href=")
for line2 in spl:
spl2 = line2.split(">")[0].strip('""')
if spl2.endswith(".png") or spl2.endswith(".gif") or spl2.endswith(".jpg"):
#print(spl2)
html_out+=f'
"
return html_in
#from datetime import date, timedelta, datetime
def generate_sdo_urls(date1_str: str, date2_str: str) -> list[str]:
"""
Generates a list of SDO browse image URLs for all days
inclusive of date1_str and date2_str.
The URL format is assumed to be:
https://sdo.gsfc.nasa.gov/assets/img/browse/YYYY/MM/DD/
Args:
date1_str: Start date in "YYYYMMDD" format (e.g., "20230115").
date2_str: End date in "YYYYMMDD" format (e.g., "20230117").
Returns:
A list of URL strings.
Returns an empty list if date1_str > date2_str or if dates are invalid.
"""
url_box = []
base_url = "https://sdo.gsfc.nasa.gov/assets/img/browse"
try:
# Convert input strings to date objects
# datetime.strptime creates a datetime object, .date() gets just the date part
start_date = datetime.datetime.strptime(date1_str[:8], "%Y%m%d").date()
end_date = datetime.datetime.strptime(date2_str[:8], "%Y%m%d").date()
except ValueError:
print(f"Error: Invalid date format. Please use YYYYMMDD. Received: '{date1_str}', '{date2_str}'")
return [] # Return empty list for invalid date format
# Handle cases where start_date is after end_date
if start_date > end_date:
print(f"Warning: Start date ({date1_str}) is after end date ({date2_str}). Returning an empty list.")
return []
current_date = start_date
while current_date <= end_date:
# Format year, month, and day with leading zeros if necessary
# .year, .month, .day are integers
year_str = f"{current_date.year:04}" # Ensures YYYY format (though usually not needed for year)
month_str = f"{current_date.month:02}" # Ensures MM format (e.g., 1 -> 01)
day_str = f"{current_date.day:02}" # Ensures DD format (e.g., 5 -> 05)
# Construct the URL
out_url = f"{base_url}/{year_str}/{month_str}/{day_str}/"
url_box.append(out_url)
# Move to the next day
current_date += datetime.timedelta(days=1)
return url_box
def count_days_og(date1,date2):
url_box=[]
in_year=f"{date1[0:4]}"
in_month=f"{date1[4:6]}"
in_day=f"{date1[6:8]}"
end_year=f"{date2[0:4]}"
end_month=f"{date2[4:6]}"
end_day=f"{date2[6:8]}"
years_rem,months_rem,days_rem=(0,0,0)
og_days_rem=days_rem
i_in_year,i_in_month,i_in_day,i_end_year,i_end_month,i_end_day=int(in_year),int(in_month),int(in_day),int(end_year),int(end_month),int(end_day)
days_json={"year": 0, "month": 0, "day": 0}
if i_end_year > i_in_year:
years_rem = i_end_year-i_in_year
if i_end_month > i_in_month:
months_rem = 12 - i_in_month
if i_end_day > i_in_day:
og_days_rem = month_dict[in_month] - i_in_day
if years_rem > 0:
for ii in list(range(0,years_raw)):
months_rem+=years_rem*12
out_year = in_year+ii
for i in list(range(0,months_rem)):
month_day_cnt = month_dict[str(int(in_month)+i)]
for io in list(range(0,month_day_cnt)):
days_rem += month_day_cnt
out_url=f"https://sdo.gsfc.nasa.gov/assets/img/browse/{out_year}/{i}/{io}/"
print(out_url)
url_box.append(out_url)
months_raw = 0
if months_rem > 0:
out_year = in_year
for i in list(range(0,months_rem)):
month_day_cnt = month_dict[str(int(in_month)+i)]
for io in list(range(0,month_day_cnt)):
days_rem += month_day_cnt
out_url=f"https://sdo.gsfc.nasa.gov/assets/img/browse/{out_year}/{i}/{io}/"
print(out_url)
url_box.append(out_url)
og_days_rem=0
if og_days_rem > 0:
for io in list(range(0,og_days_rem)):
days_rem += month_day_cnt
out_url=f"https://sdo.gsfc.nasa.gov/assets/img/browse/{end_year}/{end_month}/{io}/"
print(out_url)
url_box.append(out_url)
def nasa_sdo_images(obj,size,date1,date2):
url_box=[]
html_in=f"
")
in_year=f"{date1[0:4]}"
in_month=f"{date1[4:6]}"
in_day=f"{date1[6:8]}"
end_year=f"{date2[0:4]}"
end_month=f"{date2[4:6]}"
end_day=f"{date2[6:8]}"
sdo_urls = generate_sdo_urls(date1,date2)
print(sdo_urls)
'''years_rem,months_rem,days_rem=(0,0,0)
og_days_rem=days_rem
i_in_year,i_in_month,i_in_day,i_end_year,i_end_month,i_end_day=int(in_year),int(in_month),int(in_day),int(end_year),int(end_month),int(end_day)
days_json={"year": 0, "month": 0, "day": 0}
if i_end_year > i_in_year:
years_rem = i_end_year-i_in_year
if i_end_month > i_in_month:
months_rem = 12 - i_in_month
if i_end_day > i_in_day:
og_days_rem = month_dict[in_month] - i_in_day
if years_rem > 0:
for ii in list(range(0,years_raw)):
months_rem+=years_rem*12
out_year = in_year+ii
for i in list(range(0,months_rem)):
month_day_cnt = month_dict[str(int(in_month)+i)]
for io in list(range(0,month_day_cnt)):
days_rem += month_day_cnt
out_url=f"https://sdo.gsfc.nasa.gov/assets/img/browse/{out_year}/{i}/{io}/"
print(out_url)
url_box.append(out_url)
months_raw = 0
if months_rem > 0:
out_year = in_year
for i in list(range(0,months_rem)):
month_day_cnt = month_dict[str(int(in_month)+i)]
for io in list(range(0,month_day_cnt)):
days_rem += month_day_cnt
out_url=f"https://sdo.gsfc.nasa.gov/assets/img/browse/{out_year}/{i}/{io}/"
print(out_url)
url_box.append(out_url)
og_days_rem=0
if og_days_rem > 0:
for io in list(range(0,og_days_rem)):
days_rem += io
out_url=f"https://sdo.gsfc.nasa.gov/assets/img/browse/{end_year}/{end_month}/{io}/"
print(out_url)
url_box.append(out_url)'''
file_name="DATE_TIME_SIZE_TOOL.jpg"
out_box=[]
sdo_urls.sort(reverse=True)
for num, link in enumerate(sdo_urls):
link_box=[]
print(link)
#sdo_source_format = f"https://sdo.gsfc.nasa.gov/assets/img/browse/{in_year}/{in_month}/{in_day}/"
sdo_source_format = link
#get_url=sdo_source_format
feed1 = requests.get(link)
#print(get_url)
if "All" in size:
size = sdo_size
if "All" in obj:
obj = sdo_obj
# Parse the HTML content using BeautifulSoup
soup = bs4.BeautifulSoup(feed1.content, 'html.parser')
#print(soup)
anchor_elements = soup.find_all('a')
for element in anchor_elements:
link_box.append(element.get('href'))
link_box.sort(reverse=True)
#for element in anchor_elements:
for href in link_box:
#print(href)
#href=element.get('href')
if href.endswith('.jpg'):
for o in obj:
for s in size:
ls=href.split("_")
#print(ls[1][0:4])
#print(date1[8:13])
if ls[1][0:4]>=date1[8:13]:
src_obj=ls[3].split('.jpg')[0]
if src_obj == o:
if int(ls[2]) == int(s):
print(f"{link}{href}")
out_box.append(f'{link}{href}')
html_in+=f'
")
in_year=f"{date2[0:4]}"
in_month=f"{date2[4:6]}"
in_day=f"{date2[6:8]}"
file_name="DATE_TIME_SIZE_TOOL.jpg"
sdo_source_format = f"https://sdo.gsfc.nasa.gov/assets/img/browse/{in_year}/{in_month}/{in_day}/"
get_url=sdo_source_format
print(get_url)
feed1 = requests.get(get_url)
if "All" in size:
size = sdo_size
if "All" in obj:
obj = sdo_obj
link_box=[]
soup = bs4.BeautifulSoup(feed1.content, 'html.parser')
anchor_elements = soup.find_all('a')
#anchor_elements.sort()
cnt=1
max_cnt=ret_num
for element in anchor_elements:
href=element.get('href')
if href.endswith('.jpg'):
for o in obj:
for s in size:
ls=href.split("_")
#print(ls[1][0:4])
#print(date1[8:13])
if ls[1][0:4]>=date1[8:13]:
src_obj=ls[3].split('.jpg')[0]
if src_obj == o:
if int(ls[2]) == int(s):
link_box.append(href)
#print(link_box)
#print("$$$$$$$$$$$$$$$$$")
link_box.sort(reverse=True)
#print(link_box)
out_box=[]
for ea in link_box:
if cnt<=max_cnt:
out_link=f'{sdo_source_format}{ea}'
out_box.append(out_link)
cnt+=1
html_in+=f'
""")
with gr.Tab("NOAA"):
with gr.Tab("Compilation"):
first_comp_btn=gr.Button("Load")
first_comp_img=gr.Image()
with gr.Tab("Images"):
first_btn=gr.Button("Load")
html_im=gr.HTML()
with gr.Tab("Animations"):
anim_btn=gr.Button()
anim_out=gr.HTML()
file_out=gr.Files()
with gr.Tab("Raw"):
with gr.Row():
drop1=gr.Dropdown()
drop2=gr.Dropdown()
drop3=gr.Dropdown()
drop4=gr.Dropdown()
with gr.Row():
drop5=gr.Dropdown()
drop6=gr.Dropdown()
drop7=gr.Dropdown()
drop8=gr.Dropdown()
load_btn=gr.Button("Load")
html_raw=gr.HTML()
links=gr.JSON()
with gr.Tab("NASA"):
with gr.Tab("SDO Images"):
with gr.Row():
gr.Markdown("