From 036fc5997bbaafe3fef9dc72722dd5d427282e55 Mon Sep 17 00:00:00 2001 From: Ariel Pontes Date: Mon, 10 Feb 2020 13:18:31 +0200 Subject: [PATCH] Skip directories that don't exist --- app/parsers/ted.py | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/app/parsers/ted.py b/app/parsers/ted.py index 5829e28..2863f70 100644 --- a/app/parsers/ted.py +++ b/app/parsers/ted.py @@ -49,38 +49,25 @@ def ftp_download_tender_archive(self, tenders): def ftp_download_latest_archives(self): ftp = self.ftp_login() + today = date.today() last_date = self.last_ted_update or self.last_update('TED') - last_month = last_date.strftime('%m') - last_year = last_date.strftime('%Y') - ftp.cwd(f'/daily-packages/{last_year}/{last_month}') + while last_date <= today: - archives = ftp.nlst() - today = date.today() + last_month = last_date.strftime('%m') + last_year = last_date.strftime('%Y') - while last_date <= today: - self.download_archive(ftp, last_date, archives) + try: + ftp.cwd(f'/daily-packages/{last_year}/{last_month}') + archives = ftp.nlst() + self.download_archive(ftp, last_date, archives) + except error_perm as e: + # Directory doesn't exist + logging.warning(e) + pass last_date += timedelta(1) - if last_year != last_date.strftime('%Y'): - last_year = last_date.strftime('%Y') - last_month = last_date.strftime('%m') - try: - ftp.cwd('../../{}/{}'.format(last_year, last_month)) - archives = ftp.nlst() - except error_perm as e: - logging.warning(e) - pass - elif last_month != last_date.strftime('%m'): - last_month = last_date.strftime('%m') - try: - ftp.cwd('../{}'.format(last_month)) - archives = ftp.nlst() - except error_perm as e: - logging.warning(e) - pass - quit_or_close(ftp) def ftp_download_daily_archives(self):