Skip to content

Commit

Permalink
replace_tokens.py only inserts DATE if one doesn't already exist. All…
Browse files Browse the repository at this point in the history
…ows for dates to be explicitly provided
  • Loading branch information
mikej888 committed Aug 9, 2018
1 parent 53ffa5e commit 9b2be80
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions scripts/replace_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
the key.
Any occurrences of a special token "%DATE%" are replaced with
the current date in form, for example, "23 July 2018".
the current date in form, for example, "23 July 2018". Howver,
if a DATE is already defined in the configuration file then that
is used instead.
"""

# Copyright (c) 2018 The University of Edinburgh
Expand Down Expand Up @@ -55,6 +57,8 @@ def load_tokens(token_file):
A special key-value pair, %DATE%,<CURRENT-DATE> is also added,
where the current date is of form, for example, "23 July 2018".
However, if a DATE is already defined in the configuration file
then that is used instead.
:param token_file: file name
:type token_file: str or unicode
Expand All @@ -66,7 +70,8 @@ def load_tokens(token_file):
tokens = {}
for (key, value) in list(user_tokens.items()):
tokens["%%%s%%" % key] = value
tokens["%DATE%"] = datetime.datetime.now().strftime("%d %B %Y")
if "%DATE%" not in list(tokens.keys()):
tokens["%DATE%"] = datetime.datetime.now().strftime("%d %B %Y")
return tokens


Expand Down

0 comments on commit 9b2be80

Please sign in to comment.