From 31fb63afb8ef1859f9f9ecdc94a7bb15a3137d4b Mon Sep 17 00:00:00 2001 From: laurentheirendt <laurent.heirendt@uni.lu> Date: Thu, 20 Jun 2019 20:34:40 +0200 Subject: [PATCH] check date and generate the directory --- contribute.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/contribute.py b/contribute.py index 1081fdb9..56e4815f 100644 --- a/contribute.py +++ b/contribute.py @@ -1,14 +1,33 @@ import click import datetime +import os @click.command() @click.option('--date', default=datetime.datetime.today().strftime('%Y-%m-%d'), help='Date of the presentation - format: YYYY-MM-DD') @click.option('--name', default='myPresentation', help='Short name of the presentation.') + def copyTemplate(date, name): """Copies the template folder""" + + # validate the date + validateDate(date) + + # get the directory + mainDir = date[:4] + + # print out a summary click.echo(' > Date: {0}' . format(date)) click.echo(' > Name: {0}' . format(name)) + click.echo(' > Directory: {0}' . format(os.path.join(os.getcwd(), mainDir, name))) + + +def validateDate(input): + try: + datetime.datetime.strptime(input, '%Y-%m-%d') + except ValueError: + print('The date {} is invalid'.format(input)) + raise if __name__ == '__main__': copyTemplate() -- GitLab