'
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}'
if not get_url.endswith('.json'):
feed1 = requests.get(get_url)
spl = feed1.text.split("href=")
for line in spl:
spl2 = line.split(">")[0]
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)
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"):
html_out+=f'
'
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"):
html_out+=f'
"
in_year=f"{date2[0:4]}"
in_month=f"{date2[4:6]}"
in_day=f"{date2[6:8]}"
sdo_source_format = f"https://sdo.gsfc.nasa.gov/assets/img/browse/{in_year}/{in_month}/{in_day}/"
get_url=sdo_source_format
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')
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("_")
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)
link_box.sort(reverse=True)
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'
"
return html_in, out_box
def run():
out=make_tree()
im_html=get_images()
return im_html
def get_date(year1,month1,day1,hour1,minute1,year2,month2,day2,hour2,minute2):
try:
start_dt = datetime.datetime(int(year1), int(month1), int(day1), int(hour1), int(minute1))
end_dt = datetime.datetime(int(year2), int(month2), int(day2), int(hour2), int(minute2))
date1 = start_dt.strftime('%Y%m%d%H%M')
date2 = end_dt.strftime('%Y%m%d%H%M')
return date1, date2
except ValueError as e:
print(f"Error creating date: {e}")
return None, None
def comp_combine(inp_ims: list,comp_col,comp_row,resize=False):
im_box=[]
v_box=[]
rows=comp_row
cols=comp_col
if not type(inp_ims)==type([]):
try:
inp_ims=eval(inp_ims)
except:
return None
if not inp_ims:
return None
for i,im in enumerate(inp_ims):
urllib.request.urlretrieve(im, f"tmp-{i}.jpg")
if resize:
pil_im = Image.open(f'tmp-{i}.jpg')
pil_im = pil_im.resize((int(resize[0]),int(resize[1])),resample=Image.Resampling.LANCZOS).convert('RGB')
pil_im.save(f'tmp-{i}.jpg')
im_box.append(f"tmp-{i}.jpg")
im_cnt=len(im_box)
cnt=1
for rr in range(rows):
if cnt > im_cnt: break
col_start=[im_box[cnt-1]]
for cc in range(cols-1):
try:
if cnt >= im_cnt: break
col_out=get_concat_h_cut(col_start[0],im_box[cnt])
col_start[0]=col_out
cnt+=1
except Exception as e:
pass
v_box.append(col_start[0])
if not v_box:
return None
v_cnt=1
v_box_cnt=len(v_box)
v_start=[v_box[0]]
for vv in range(v_box_cnt-1):
v_out=get_concat_v_cut(v_start[0],v_box[v_cnt])
v_start[0]=v_out
v_cnt+=1
return v_start[0]
def comp_1(comp_list=comp_list,col=3,row=4,resize=[640,450]):
outp=comp_combine(comp_list,col,row,resize)
return (outp)
def get_time():
now = datetime.datetime.utcnow()
datetimestamp_str = now.strftime('%Y-%m-%d %H:%M:%S')
html_out = f"""
Current: {datetimestamp_str} UTC
"""
return (gr.update(value=html_out), now.year, now.month, now.day, now.hour, now.minute,
now.year, now.month, now.day, now.hour, now.minute)
with gr.Blocks() as app:
url_list=gr.State([])
now = datetime.datetime.utcnow()
time_html=gr.HTML()
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("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("