Skip to content

Commit

Permalink
Merge pull request #242 from eaudeweb/fix-no-dir
Browse files Browse the repository at this point in the history
Skip directories that don't exist
  • Loading branch information
arielpontes authored Feb 10, 2020
2 parents ddf9898 + 036fc59 commit 9634691
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions app/parsers/ted.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 9634691

Please sign in to comment.