-
Notifications
You must be signed in to change notification settings - Fork 0
/
ghtml.py
44 lines (32 loc) · 896 Bytes
/
ghtml.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
#!d:\python27\python.exe
# -*- coding: utf-8 -*-
import pystache
import mysql.connector
config = {
'user': 'root',
'password': '',
'host': '127.0.0.1',
'database': 'mcheck',
'raise_on_warnings': True,
}
cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
cursor.execute("SELECT date, description, amount FROM register")
all_data = {
'title':u'Список'.encode('utf-8'),
'items':[],
}
for (date, description, amount) in cursor:
all_data['items'].append({
'date':u"{:%d %b %Y}".format(date),
'amount':u"{:.2f}".format(amount),
'description':u"{}".format(description),
})
cursor.close()
cnx.close()
renderer = pystache.Renderer()
renderer.file_encoding = 'utf-8'
renderer.string_encoding = 'utf-8'
print "Content-Type: text/html"
print ""
print renderer.render_path('ghtml.mustache', all_data).encode('utf8')