From 38bc6b250dc919a34cfb69600addd2726403e9b9 Mon Sep 17 00:00:00 2001 From: zhangcsh <34929621+Russyz@users.noreply.github.com> Date: Fri, 11 Mar 2022 10:43:53 +0800 Subject: [PATCH] Update data_download.py define 'ftp_access' --- slrfield/utils/data_download.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/slrfield/utils/data_download.py b/slrfield/utils/data_download.py index 32e405d..dcc0506 100644 --- a/slrfield/utils/data_download.py +++ b/slrfield/utils/data_download.py @@ -6,6 +6,23 @@ from .try_download import tqdm_ftp +# ftp access +def ftp_access(server,src_dir): + """ + Access the ftp server to download the EOP file. + + Usage: + >>> ftp_access(server,src_dir) + + Parameters: + server -> [str] Server address + src_dir -> [str] Directory of the EOP file + """ + ftp = FTP(server) + ftp.login() + ftp.cwd(src_dir) + return ftp + def download_eop(out_days=7,dir_to=None): """ Download or update the Earth Orientation Parameters(EOP) file from IERS @@ -32,17 +49,17 @@ def download_eop(out_days=7,dir_to=None): if not path.exists(dir_to): makedirs(dir_to) if not path.exists(dir_file): - ftp_access(server,src_dir) + ftp = ftp_access(server,src_dir) desc = "Downloading the latest EOP '{:s}' from IERS".format(file) tqdm_ftp(ftp,dir_to,file,desc) else: modified_time = datetime.fromtimestamp(path.getmtime(dir_file)) if datetime.now() > modified_time + timedelta(days=out_days): remove(dir_file) - ftp_access(server,src_dir) + ftp = ftp_access(server,src_dir) desc = "Updating EOP '{:s}' from IERS".format(file) tqdm_ftp(ftp,dir_to,file,desc) else: print("EOP '{0:s}' in {1:s} is already the latest.".format(file,dir_to)) - return dir_file \ No newline at end of file + return dir_file