From 9ac168ab9cab0078c7d28e1fa21020bf32b1afbd Mon Sep 17 00:00:00 2001 From: uh_wot <3631986-uh_wot@users.noreply.gitlab.com> Date: Sat, 2 May 2020 23:42:27 +0200 Subject: [PATCH] cleaned up formatDate function --- deemix/app/downloader.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index acedc2b..d177006 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -88,20 +88,15 @@ def downloadImage(url, path): def formatDate(date, template): - if 'YYYY' in template: - template = template.replace('YYYY', str(date['year'])) - if 'YY' in template: - template = template.replace('YY', str(date['year'])) - if 'Y' in template: - template = template.replace('Y', str(date['year'])) - if 'MM' in template: - template = template.replace('MM', str(date['month'])) - if 'M' in template: - template = template.replace('M', str(date['month'])) - if 'DD' in template: - template = template.replace('DD', str(date['day'])) - if 'D' in template: - template = template.replace('D', str(date['day'])) + elements = { + 'year': ['YYYY', 'YY', 'Y'], + 'month': ['MM', 'M'], + 'day': ['DD', 'D'] + } + for element, placeholders in elements.items(): + for placeholder in placeholders: + if placeholder in template: + template = template.replace(placeholder, str(date[element])) return template