From da72558576bd6420646bf40e80e484e155afc730 Mon Sep 17 00:00:00 2001 From: Yoav Kleinberger Date: Mon, 23 Jan 2017 01:02:38 +0200 Subject: [PATCH] appears to be working --- example.py | 8 ++++++++ example.yaml | 6 ++++++ yaml_mako.py | 8 ++++++++ 3 files changed, 22 insertions(+) create mode 100644 example.py create mode 100644 example.yaml create mode 100644 yaml_mako.py diff --git a/example.py b/example.py new file mode 100644 index 0000000..d6d3ced --- /dev/null +++ b/example.py @@ -0,0 +1,8 @@ +import yaml_mako +import pprint +import datetime + +stream = open( 'example.yaml' ) +today = datetime.date.today() +oneYearLater = today + datetime.timedelta( 1 ) +pprint.pprint( yaml_mako.load( stream, start_date = today, end_date = oneYearLater ) ) diff --git a/example.yaml b/example.yaml new file mode 100644 index 0000000..9cd97ed --- /dev/null +++ b/example.yaml @@ -0,0 +1,6 @@ +--- +name: "subscription" +details: + start time: ${start_date} + end time: ${end_date} + comment: dates should appear above after temlating diff --git a/yaml_mako.py b/yaml_mako.py new file mode 100644 index 0000000..6ff95c7 --- /dev/null +++ b/yaml_mako.py @@ -0,0 +1,8 @@ +import yaml +import mako.template + +def load( yamlSource, ** kwargs ): + content = yamlSource.read() + template = mako.template.Template( content ) + yamlContent = template.render( ** kwargs ) + return yaml.load( yamlContent )