Create a notify standardised python and html template

Hi guys/gals,

I have several python scripts running various stuff and would like to simplify the email massages for a more consistent look and feel across all the notifications… a template.
then just replace some ~ ~placeholders~ ~ that are written in to the html with the info needed to be transmitted.

configuration.yaml

- alias: x_schedule4

  trigger:
	#every 10 seconds *For Testing*
    - platform: time_pattern
      seconds: /10

    - condition: state
      entity_id: input_boolean.testing
      state: "on"

  action:
    - service: python_script.email-template.py

python_scripts/email-template.py

# Open (read) html email template file into str variable
with open('/home/homeassistant/.homeassistant/python_scripts/email-template.html', 'w') as htmlfile:
    notification_email = htmlfile.read()

str_message1 = 'data gathered and manipulated from Home Assistant'
str_message2 = 'data gathered and manipulated from Home Assistant'

# Replace email template place holders with script variables
notification_email = notification_email.replace("~~message1~~", str_message1)
notification_email = notification_email.replace("~~message2~~", str_message2)

# Send email with hass service call
hass.services.call('notify', email_info, {'title' : notification_tilte, 'html': notification_email})

python_scripts/email-template.html

<!DOCTYPE html>
<html lang="en">
<head runat="server">
	<meta charset="UTF-8">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>~~message-title~~</title>
	<style type="text/css">	

	</style>
</head>
<body>
	<div class="head">
		<h1>email alert</h1>
	</div>
	<div class="box">
		<h3>~~message1~~</h3>
	</div>
	<div class="box">
		<p>~~message2~~</p>
	</div>

	<div class="foot">
		<p>;)</p>
	</div>
</body>
</html>

This would work perfectly if ‘open’ was in RestrictedPython and defined, but it is not, so this fails.
So what options, alternatives or methods are there to achieve this and still use the python variables?

Many Thanks

AppDaemon gives you full python functionality.