Skip to content

Instantly share code, notes, and snippets.

@mega-arbuz
Last active February 9, 2019 22:56
Show Gist options
  • Save mega-arbuz/92b5de6f6ad9aea81ee311115ba9ab7e to your computer and use it in GitHub Desktop.
Save mega-arbuz/92b5de6f6ad9aea81ee311115ba9ab7e to your computer and use it in GitHub Desktop.
Compose email from template file
def get_email(app_name, app_version, app_url, changes, template_file_path):
target_subject = 1
target_body = 2
target = 0
subject = ""
body = ""
template = ""
with(open(template_file_path)) as template_file:
# Open template file and replace placeholders with data
template = template_file.read().format(
app_download_url=app_url,
change_log=changes,
app_name=app_name,
app_version=app_version
)
# Iterate over each line and collect lines marked for subject/body
for line in template.splitlines():
if line.startswith('#'):
if line.startswith('#subject'):
target = target_subject
elif line.startswith('#body'):
target = target_body
else:
if target == target_subject:
subject += line + '\n'
elif target == target_body:
body += line + '\n'
return subject.rstrip(), body.rstrip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment