forked from Thykof/template-pptx-jinja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
55 lines (45 loc) · 1.2 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import jinja2
from template_pptx_jinja.render import PPTXRendering
def main():
input_path = 'example/template.pptx'
model = {
"name": "John",
"number": 3,
"step": [
{
"name": "analysis"
},
{
"name": "design"
},
{
"name": "production"
}
],
"size": [10, 9000],
"my_table_name": "My filling table",
"my_table": [
["Hello", "World"],
["Python", "Programming"],
["Data", "Science"],
["Machine", "Learning"],
["Artificial", "Intelligence"]
]
}
pictures = {
"example/model.jpg": "example/image.jpg"
}
data = {
'model': model,
'pictures': pictures
}
def plural(input, word_ending):
return word_ending if input > 0 else ''
jinja2_env = jinja2.Environment()
jinja2_env.filters['plural'] = plural
output_path = 'example/presentation_generated.pptx'
rendering = PPTXRendering(input_path, data, output_path, jinja2_env)
message = rendering.process()
print(message)
if __name__ == '__main__':
main()