restructured the read in / sort order.
This commit is contained in:
15
app.py
15
app.py
@@ -27,7 +27,20 @@ import gpxpy
|
|||||||
# === Helper Functions ===
|
# === Helper Functions ===
|
||||||
def list_gpx_files():
|
def list_gpx_files():
|
||||||
folder = './gpx_files'
|
folder = './gpx_files'
|
||||||
return [{'label': f, 'value': os.path.join(folder, f)} for f in os.listdir(folder) if f.endswith('.gpx')]
|
#return [{'label': f, 'value': os.path.join(folder, f)} for f in os.listdir(folder) if f.endswith('.gpx')]
|
||||||
|
files = [f for f in os.listdir(folder) if f.endswith('.gpx')]
|
||||||
|
|
||||||
|
# Extract date from the start of the filename and sort descending
|
||||||
|
def extract_date(filename):
|
||||||
|
try:
|
||||||
|
return datetime.datetime.strptime(filename[:10], '%Y-%m-%d')
|
||||||
|
except ValueError:
|
||||||
|
return datetime.datetime.min # Put files without a valid date at the end
|
||||||
|
|
||||||
|
files.sort(key=extract_date, reverse=True)
|
||||||
|
|
||||||
|
return [{'label': f, 'value': os.path.join(folder, f)} for f in files]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def haversine(lon1, lat1, lon2, lat2):
|
def haversine(lon1, lat1, lon2, lat2):
|
||||||
|
|||||||
Reference in New Issue
Block a user