1
- """Download files modified in the last 24 hours from the specified ftp server."""
1
+ """Download files from the specified ftp server."""
2
2
3
3
# standard
4
4
import datetime
@@ -16,21 +16,19 @@ def print_callback(filename, bytes_so_far, bytes_total):
16
16
print (f'{ filename } transfer: { rough_percent_transferred } %' )
17
17
18
18
19
- def get_files_from_dir (sftp , out_path ):
20
- """Download files from sftp server that have been uploaded in last day.
19
+ def get_files_from_dir (sftp , filedate , out_path ):
20
+ """Download files from sftp server tagged with the specified day.
21
21
22
22
Args:
23
23
sftp: SFTP Session from Paramiko client
24
+ filedate: YYYYmmdd string for which the files are named
24
25
out_path: Path to local directory into which to download the files
25
26
"""
26
- current_time = datetime .datetime .now ()
27
-
28
27
# go through files in recieving dir
29
28
filepaths_to_download = {}
30
29
for fileattr in sftp .listdir_attr ():
31
- file_time = datetime .datetime .fromtimestamp (fileattr .st_mtime )
32
30
filename = fileattr .filename
33
- if current_time - file_time < datetime . timedelta ( days = 1 ) and \
31
+ if fileattr . filename . startswith ( filedate ) and \
34
32
not path .exists (path .join (out_path , filename )):
35
33
filepaths_to_download [filename ] = path .join (out_path , filename )
36
34
@@ -43,10 +41,11 @@ def get_files_from_dir(sftp, out_path):
43
41
sftp .get (infile , outfile , callback = callback_for_filename )
44
42
45
43
46
- def download_covid (out_path , ftp_conn ):
44
+ def download_covid (filedate , out_path , ftp_conn ):
47
45
"""Download files necessary to create chng-covid signal from ftp server.
48
46
49
47
Args:
48
+ filedate: YYYYmmdd string for which the files are named
50
49
out_path: Path to local directory into which to download the files
51
50
ftp_conn: Dict containing login credentials to ftp server
52
51
"""
@@ -62,20 +61,21 @@ def download_covid(out_path, ftp_conn):
62
61
sftp = client .open_sftp ()
63
62
64
63
sftp .chdir ('/dailycounts/All_Outpatients_By_County' )
65
- get_files_from_dir (sftp , out_path )
64
+ get_files_from_dir (sftp , filedate , out_path )
66
65
67
66
sftp .chdir ('/dailycounts/Covid_Outpatients_By_County' )
68
- get_files_from_dir (sftp , out_path )
67
+ get_files_from_dir (sftp , filedate , out_path )
69
68
70
69
finally :
71
70
if client :
72
71
client .close ()
73
72
74
73
75
- def download_cli (out_path , ftp_conn ):
74
+ def download_cli (filedate , out_path , ftp_conn ):
76
75
"""Download files necessary to create chng-cli signal from ftp server.
77
76
78
77
Args:
78
+ filedate: YYYYmmdd string for which the files are named
79
79
out_path: Path to local directory into which to download the files
80
80
ftp_conn: Dict containing login credentials to ftp server
81
81
"""
@@ -91,19 +91,19 @@ def download_cli(out_path, ftp_conn):
91
91
sftp = client .open_sftp ()
92
92
93
93
sftp .chdir ('/dailycounts/All_Outpatients_By_County' )
94
- get_files_from_dir (sftp , out_path )
94
+ get_files_from_dir (sftp , filedate , out_path )
95
95
96
96
sftp .chdir ('/dailycounts/Flu_Patient_Count_By_County' )
97
- get_files_from_dir (sftp , out_path )
97
+ get_files_from_dir (sftp , filedate , out_path )
98
98
99
99
sftp .chdir ('/dailycounts/Mixed_Patient_Count_By_County' )
100
- get_files_from_dir (sftp , out_path )
100
+ get_files_from_dir (sftp , filedate , out_path )
101
101
102
102
sftp .chdir ('/dailycounts/Flu_Like_Patient_Count_By_County' )
103
- get_files_from_dir (sftp , out_path )
103
+ get_files_from_dir (sftp , filedate , out_path )
104
104
105
105
sftp .chdir ('/dailycounts/Covid_Like_Patient_Count_By_County' )
106
- get_files_from_dir (sftp , out_path )
106
+ get_files_from_dir (sftp , filedate , out_path )
107
107
108
108
finally :
109
109
if client :
0 commit comments