Skip to content

Commit

Permalink
Merge pull request #29 from Legilibre/fix-download
Browse files Browse the repository at this point in the history
Improve download
  • Loading branch information
Changaco authored Feb 17, 2018
2 parents 7e2834c + 7b55483 commit 90b3772
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions legi/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@


def download_legi(dst_dir):
if not os.path.exists(dst_dir):
os.mkdir(dst_dir)
local_files = {filename: {} for filename in os.listdir(dst_dir)}
ftph = ftplib.FTP()
ftph.connect(DILA_FTP_HOST, DILA_FTP_PORT)
ftph.login()
ftph.cwd(DILA_LEGI_DIR)
remote_files = {filename: {} for filename in ftph.nlst() if 'legi_' in filename}
local_set = set(local_files.keys())
remote_set = set(remote_files.keys())
common_files = list(local_set & remote_set)
missing_files = list(remote_set - local_set)
remote_files = [filename for filename in ftph.nlst() if 'legi_' in filename]
common_files = [f for f in remote_files if f in local_files]
missing_files = [f for f in remote_files if f not in local_files]
remote_files = {filename: {} for filename in remote_files}
for filename in common_files:
local_files[filename]['size'] = os.path.getsize(
os.path.join(dst_dir, filename)
Expand Down

0 comments on commit 90b3772

Please sign in to comment.