Files: 89a367fda7adddc793a2ebab82ecd312a098aebe / steps / template.py
1294 bytesRaw
1 | import shutil |
2 | import os |
3 | |
4 | def make_directory(details): |
5 | """Make a new folder specific for invitee within this directory, then add an index.html and |
6 | stylesheet.css file for it.""" |
7 | name = details['recipient'].replace(" ","-").lower() |
8 | path = 'invites/{}'.format(name) |
9 | if not os.path.exists(path): |
10 | os.makedirs(path) |
11 | shutil.copy2('resources/stylesheet.css', path) |
12 | shutil.copy2('resources/index.html', path) |
13 | |
14 | |
15 | def filled_out_template(details): |
16 | """Take the details entered in the script and add them to the index.html template.""" |
17 | with open('resources/template.html', 'r') as template: |
18 | the_page = template.read() |
19 | return the_page.format(**details) |
20 | |
21 | def create_index_file(details): |
22 | """Convert the filled out template file into the invitees' index.html file""" |
23 | name = details['recipient'].replace(" ","-").lower() |
24 | index_file = 'invites/{}/index.html'.format(name) |
25 | with open(index_file, "w") as target_file: |
26 | target_file.write(filled_out_template(details)) |
27 | |
28 | def main(details): |
29 | """Make a new directory for the invitee, then add a stylesheet and custom index.html file to |
30 | this directory.""" |
31 | make_directory(details) |
32 | filled_out_template(details) |
33 | create_index_file(details) |
34 | |
35 | if __name__ == "__main__": |
36 | main() |
37 |
Built with git-ssb-web