optimizations
This commit is contained in:
@@ -29,8 +29,16 @@ class CopernicusDownloader:
|
|||||||
self.download(self.output_file)
|
self.download(self.output_file)
|
||||||
self.apply_setreftime(self.output_file,self.prepared_file)
|
self.apply_setreftime(self.output_file,self.prepared_file)
|
||||||
self.convert_to_grib2(self.prepared_file,self.output_grib)
|
self.convert_to_grib2(self.prepared_file,self.output_grib)
|
||||||
|
self.file_remove(self.output_file)
|
||||||
return self.output_grib
|
return self.output_grib
|
||||||
|
|
||||||
|
def file_remove(self,file):
|
||||||
|
if os.path.exists(file):
|
||||||
|
os.remove(file)
|
||||||
|
print(f"✅ File removed : {file}")
|
||||||
|
else:
|
||||||
|
print(f"❌ File {file} does not exist.")
|
||||||
|
|
||||||
def download(self,outfile):
|
def download(self,outfile):
|
||||||
today = datetime.utcnow()
|
today = datetime.utcnow()
|
||||||
start_date = today.strftime("%Y-%m-%dT00:00:00")
|
start_date = today.strftime("%Y-%m-%dT00:00:00")
|
||||||
|
|||||||
28
iface.py
28
iface.py
@@ -7,6 +7,7 @@ import os
|
|||||||
import platform
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
import configparser
|
import configparser
|
||||||
|
import webbrowser
|
||||||
from math import log, tan, radians, pi, degrees, atan, sinh
|
from math import log, tan, radians, pi, degrees, atan, sinh
|
||||||
|
|
||||||
from downloader import CopernicusDownloader
|
from downloader import CopernicusDownloader
|
||||||
@@ -16,7 +17,7 @@ CONFIG_FILE = "config.ini"
|
|||||||
class MapSelector:
|
class MapSelector:
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
self.root = root
|
self.root = root
|
||||||
self.root.title("Copernicus Marine Downloader")
|
self.root.title("Surface Current Downloader")
|
||||||
|
|
||||||
self.config = configparser.ConfigParser()
|
self.config = configparser.ConfigParser()
|
||||||
self.load_config()
|
self.load_config()
|
||||||
@@ -26,9 +27,11 @@ class MapSelector:
|
|||||||
|
|
||||||
self.frame_download = ttk.Frame(self.notebook)
|
self.frame_download = ttk.Frame(self.notebook)
|
||||||
self.frame_config = ttk.Frame(self.notebook)
|
self.frame_config = ttk.Frame(self.notebook)
|
||||||
|
self.frame_about = ttk.Frame(self.notebook)
|
||||||
|
|
||||||
self.notebook.add(self.frame_download, text="Téléchargement")
|
self.notebook.add(self.frame_download, text="Download Manager")
|
||||||
self.notebook.add(self.frame_config, text="Configuration")
|
self.notebook.add(self.frame_config, text="Configuration")
|
||||||
|
self.notebook.add(self.frame_about, text="About")
|
||||||
|
|
||||||
self.downloader = CopernicusDownloader(
|
self.downloader = CopernicusDownloader(
|
||||||
username=self.config.get("AUTH", "username", fallback=""),
|
username=self.config.get("AUTH", "username", fallback=""),
|
||||||
@@ -108,7 +111,7 @@ class MapSelector:
|
|||||||
|
|
||||||
self.duration_var = tk.StringVar(value="3")
|
self.duration_var = tk.StringVar(value="3")
|
||||||
ttk.Label(params_frame, text="Days").grid(row=0, column=6)
|
ttk.Label(params_frame, text="Days").grid(row=0, column=6)
|
||||||
ttk.Combobox(params_frame, textvariable=self.duration_var, values=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"], width=5).grid(row=1, column=6)
|
ttk.Combobox(params_frame, textvariable=self.duration_var, values=["1", "2", "3", "4", "5", "6", "7", "8", "9"], width=5).grid(row=1, column=6)
|
||||||
|
|
||||||
btn_frame = ttk.Frame(self.frame_download)
|
btn_frame = ttk.Frame(self.frame_download)
|
||||||
btn_frame.pack(pady=5)
|
btn_frame.pack(pady=5)
|
||||||
@@ -182,14 +185,21 @@ class MapSelector:
|
|||||||
self.redraw_rectangle_from_coords()
|
self.redraw_rectangle_from_coords()
|
||||||
|
|
||||||
|
|
||||||
|
def open_link(self, event=None):
|
||||||
|
webbrowser.open_new("https://data.marine.copernicus.eu/register")
|
||||||
|
|
||||||
def setup_config_tab(self):
|
def setup_config_tab(self):
|
||||||
frame = self.frame_config
|
frame = self.frame_config
|
||||||
|
|
||||||
ttk.Label(frame, text="Nom d'utilisateur Copernicus Marine:").pack(pady=5)
|
ttk.Label(frame, text="Use the credential of your account ").pack(pady=5)
|
||||||
|
account_link = tk.Label(frame, text="register on https://data.marine.copernicus.eu/register",fg="blue",cursor="hand2")
|
||||||
|
account_link.pack(pady=5)
|
||||||
|
account_link.bind("<Button-1>", self.open_link)
|
||||||
|
ttk.Label(frame, text="Copernicus Marine 'username'").pack(pady=5)
|
||||||
self.username_var = tk.StringVar(value=self.config.get("AUTH", "username", fallback=""))
|
self.username_var = tk.StringVar(value=self.config.get("AUTH", "username", fallback=""))
|
||||||
ttk.Entry(frame, textvariable=self.username_var, width=30).pack()
|
ttk.Entry(frame, textvariable=self.username_var, width=30).pack()
|
||||||
|
|
||||||
ttk.Label(frame, text="Mot de passe:").pack(pady=5)
|
ttk.Label(frame, text="Copernicus Marine 'password'").pack(pady=5)
|
||||||
self.password_var = tk.StringVar(value=self.config.get("AUTH", "password", fallback=""))
|
self.password_var = tk.StringVar(value=self.config.get("AUTH", "password", fallback=""))
|
||||||
ttk.Entry(frame, textvariable=self.password_var, show="*", width=30).pack()
|
ttk.Entry(frame, textvariable=self.password_var, show="*", width=30).pack()
|
||||||
|
|
||||||
@@ -309,10 +319,10 @@ class MapSelector:
|
|||||||
lon_max = float(self.lon2_var.get())
|
lon_max = float(self.lon2_var.get())
|
||||||
days = int(self.duration_var.get())
|
days = int(self.duration_var.get())
|
||||||
except ValueError:
|
except ValueError:
|
||||||
messagebox.showerror("Erreur", "Veuillez entrer des coordonnées et durée valides.")
|
messagebox.showerror("❌ Erreur", "Veuillez entrer des coordonnées et durée valides.")
|
||||||
return
|
return
|
||||||
self.progress.start(10)
|
self.progress.start(10)
|
||||||
self.status.config(text="Téléchargement en cours...")
|
self.status.config(text="✅ Téléchargement en cours...")
|
||||||
threading.Thread(target=self.download, args=(lat_min, lat_max, lon_min, lon_max, days), daemon=True).start()
|
threading.Thread(target=self.download, args=(lat_min, lat_max, lon_min, lon_max, days), daemon=True).start()
|
||||||
|
|
||||||
def download(self, lat_min, lat_max, lon_min, lon_max, days):
|
def download(self, lat_min, lat_max, lon_min, lon_max, days):
|
||||||
@@ -321,9 +331,9 @@ class MapSelector:
|
|||||||
grib_path = self.downloader.retrieve_grib2(lat_min, lat_max, lon_min, lon_max, days)
|
grib_path = self.downloader.retrieve_grib2(lat_min, lat_max, lon_min, lon_max, days)
|
||||||
#self.status.config(text="Conversion en GRIB2 en cours...")
|
#self.status.config(text="Conversion en GRIB2 en cours...")
|
||||||
#grib_path = self.downloader.convert_to_grib2()
|
#grib_path = self.downloader.convert_to_grib2()
|
||||||
self.status.config(text=f"Téléchargement et conversion terminés : {os.path.basename(grib_path)}")
|
self.status.config(text=f"✅ Téléchargement et conversion terminés : {os.path.basename(grib_path)}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.status.config(text=f"Erreur : {e}")
|
self.status.config(text=f"❌ Erreur : {e}")
|
||||||
finally:
|
finally:
|
||||||
self.progress.stop()
|
self.progress.stop()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user