-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_page_error.py
35 lines (27 loc) · 991 Bytes
/
generate_page_error.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
import pathlib
import locale
from datetime import datetime
from settings import CUSTOM_LOCALE
from funcs import _
def generatePageError(errorMsg):
lastUpdate = datetime.now()
with open('page/templates/error.html', 'r') as file:
templateHTML = file.read()
file.close()
replaceStrings = {
'HTML_LANG': locale.getlocale()[0],
'PAGE_TITLE': _('Family calendar'),
'ERROR_MESSAGE': errorMsg,
'LAST_UPDATE_LEGEND': _('Last update'),
'LAST_UPDATE': lastUpdate.strftime('%x %X')
}
html = templateHTML
for key, value in replaceStrings.items():
html = html.replace(f'[[{key}]]', value)
with open('page/index.html', 'wt') as fout:
fout.write(html)
fout.close()
return True
if __name__ == '__main__':
locale.setlocale(locale.LC_ALL, CUSTOM_LOCALE)
generatePageError('ERROR TEST')