Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
JOSSOUD Olivier
WIM Collect
Commits
5fa61050
Commit
5fa61050
authored
Jan 22, 2020
by
JOSSOUD Olivier
Browse files
ftpopar. Use utils' compress_file() function.
parent
3de5db26
Pipeline
#57063
passed with stages
in 53 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
14 deletions
+11
-14
wimcollect/ftpopar.py
wimcollect/ftpopar.py
+11
-14
No files found.
wimcollect/ftpopar.py
View file @
5fa61050
...
...
@@ -4,6 +4,7 @@ import datetime
import
zipfile
import
wimcollect.logger
as
logger
import
wimcollect.utils
as
utils
import
wimcollect.ftp
as
ftp
...
...
@@ -27,11 +28,19 @@ class Collector(ftp.FtpCollector):
ftp_session
=
self
.
_ftp_connect_
()
source_filepath
=
self
.
base_dir
+
"/"
+
day
.
strftime
(
"%Y%m%d"
)
+
"Meteo125HR.xls"
date_str
=
day
.
strftime
(
"%Y%m%d"
)
# Build source and destination file paths
source_filepath
=
self
.
base_dir
+
"/"
+
date_str
+
"Meteo125HR.xls"
dest_filepath
=
self
.
__get_dest_filepath__
(
day
)
# Download
success
=
self
.
_ftp_download_file
(
ftp_session
,
source_filepath
,
dest_filepath
)
# Compress
if
success
:
self
.
__compress_file__
(
day
,
dest_filepath
)
self
.
logger
.
write
(
self
.
object_id
,
date_str
+
": Compressing ..."
)
utils
.
compress_file
(
dest_filepath
)
self
.
logger
.
write
(
self
.
object_id
,
date_str
+
": Done. Archive file: "
+
dest_filepath
)
ftp_session
.
quit
()
...
...
@@ -48,15 +57,3 @@ class Collector(ftp.FtpCollector):
dest_filepath
=
os
.
path
.
join
(
dest_dir
,
filename
)
return
dest_filepath
def
__compress_file__
(
self
,
day
:
datetime
.
date
,
uncompressed_filepath
:
str
):
# Compress the files
self
.
logger
.
write
(
self
.
object_id
,
day
.
strftime
(
"%Y-%m-%d"
)
+
": Compressing ..."
)
compressed_filepath
=
uncompressed_filepath
+
".lzma"
zipf
=
zipfile
.
ZipFile
(
compressed_filepath
,
'w'
,
zipfile
.
ZIP_LZMA
)
zipf
.
write
(
uncompressed_filepath
,
arcname
=
os
.
path
.
basename
(
uncompressed_filepath
))
zipf
.
close
()
if
os
.
path
.
exists
(
compressed_filepath
):
self
.
logger
.
write
(
self
.
object_id
,
day
.
strftime
(
"%Y-%m-%d"
)
+
": Done. Archive file: "
+
compressed_filepath
)
os
.
remove
(
uncompressed_filepath
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment