Python Jinja2 templater to create multiple HTML email signatures for different organization's employees.
appdirs==1.4.0
cssselect==1.0.1
cssutils==1.0.1
Jinja2==2.9.5
lxml==3.7.2
MarkupSafe==0.23
packaging==16.8
premailer==3.0.1
pyparsing==2.1.10
requests==2.13.0
six==1.10.0
Project has 4 main folders:
-
01_options
- JSON files with options for various organizations and their employees. It should contain organizations option files in the following way:01_options/01_organizations/{organization}/{organization}.json
and employees option files in the following way:01_options/02_employees/{organization}/{employee}.json
. -
02_styles
- CSS styles for specific organization stored in JSON files, stored in the following way:{organization}.j2.json
. Every CSS selector from JSON file goes to template engine to style specific organization's template with the help ofcss.j2.html
macros from the03_templates/macros
. -
03_templates
- source Jinja2 templates for email subscription that contain specific logic for rendering. It should contain template files in the following way:03_templates/{organization}.j2.html
. -
04_output
- output HTML files with rendered templates. It would contain output files in the following way:04_output/{organization}/{employee}_{organization}.html
.
You may have several organizations and their employees within the same project and render their files simultaneously or separately.
{organization}
JSON file format:
{
// Boolean option to render current organization's files or to skip rendering
"renderable": true,
// Organization's title
"org_title": "Бельканто",
// Organization's alias (used in rendering logic)
"org_alias": "belcanto",
// Width and height of organization's logo
"org_logo_width": "91",
"org_logo_height": "62",
// Motto text beyond the logo
"org_motto": "вместе мы сила!",
// Organization's web site link
"org_link": "gastroli.net",
// Message at the bottom
"org_footer": "Просьба не удалять переписку из тела письма для удобства коммуникаций",
// Test tag to force all CSS styles to be `!important`
// "normal"
// "important"
"test_tags": "important"
}
You may also create various organization JSON files within the same {organization}
folder
to render different files with slightly different options, for example:
- internal or external email communiaction (inside the company or with external partners).
- primary or secondary email messagess.
- email communiaction with Russian-speaking or English-speaking partners.
{employee}
JSON file format:
{
"emp_name_ru": "Барсуков Анатолий Геннадьевич",
"emp_occupation_ru": "Начальник кузовного цеха",
"emp_department_ru": "Кузовной цех",
"emp_name_en": "Barsukov Anatoliy Gennadyevich",
"emp_occupation_en": "Head of body workshop",
"emp_department_en": "Body workshop",
"emp_ext_tel": "806",
"emp_mob_tel": "+7(905) 654-42-83",
"emp_email": "dp@scanezh.ru"
}
You should create a new virtual environment with Python 3 and install everything from requirements.txt
.
Prepare all of the source data and simply run python render.py
.
It walks through the following steps:
-
Takes business data from different JSON files stored recursively in
01_options
folder. Each employee's file is linked with his/her organization by its parent folder's name. -
Joins each employee info with his/her organization info.
-
Renders each template according to input data. If organization's
test_tags
paramenter is set tonormal
, every CSS style will remain as it is, withimportant
each CSS style will be apended with!important
rule to strictly override any possible email client's or web interface's default CSS rules. -
Inlines all CSS styles with
premailer
. Each style within the<style>
tag goes intostyle
attribute of each corresponding HTML tag. -
Minifies code by simple regexps.
-
Saves each template into separate file in
04_output
folder within its{organization}
subfolder.