broadfield-dev commited on
Commit
5655229
·
verified ·
1 Parent(s): 3c1dab5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -3,10 +3,11 @@ import numpy as np
3
  import cv2
4
  from PIL import Image
5
  import requests
 
6
  import io
7
  import os
8
  from urllib.parse import urljoin
9
- import re
10
 
11
  # Default parameters
12
  low_int = 10
@@ -28,9 +29,18 @@ def fetch_sdo_images(max_images, ident="0745", size="1024by960", tool="ccor1"):
28
  if response.status_code != 200:
29
  return None, f"Failed to access directory {base_url}: Status {response.status_code}", 0
30
 
 
 
 
 
31
  # Extract image filenames matching the pattern {DATE}_{IDENT}_{TOOL}_{SIZE}.jpg
32
- pattern = rf"\d{{8}}_\d{{6}}_{re.escape(ident)}_{re.escape(tool)}_{re.escape(size)}\.jpg"
33
- image_files = re.findall(pattern, response.text)
 
 
 
 
 
34
 
35
  # Sort images by timestamp (most recent first)
36
  image_files = sorted(image_files, key=lambda x: x[:15], reverse=True)
 
3
  import cv2
4
  from PIL import Image
5
  import requests
6
+ from datetime import datetime
7
  import io
8
  import os
9
  from urllib.parse import urljoin
10
+ from bs4 import BeautifulSoup
11
 
12
  # Default parameters
13
  low_int = 10
 
29
  if response.status_code != 200:
30
  return None, f"Failed to access directory {base_url}: Status {response.status_code}", 0
31
 
32
+ # Parse HTML with BeautifulSoup
33
+ soup = BeautifulSoup(response.text, 'html.parser')
34
+ links = soup.find_all('a')
35
+
36
  # Extract image filenames matching the pattern {DATE}_{IDENT}_{TOOL}_{SIZE}.jpg
37
+ image_files = []
38
+ for link in links:
39
+ href = link.get('href')
40
+ if href and href.endswith(f"_{ident}_{tool}_{size}.jpg"):
41
+ # Check if the filename starts with a valid timestamp (YYYYMMDD_HHMMSS)
42
+ if len(href) >= 15 and href[:8].isdigit() and href[9:15].isdigit():
43
+ image_files.append(href)
44
 
45
  # Sort images by timestamp (most recent first)
46
  image_files = sorted(image_files, key=lambda x: x[:15], reverse=True)