-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuy.py
executable file
·46 lines (36 loc) · 1.12 KB
/
buy.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
#!/usr/bin/env python3
import sys
import cgi
import json
import datetime
import time
import os
import html
from email import utils
print("Content-type:text/html\r\n\r\n",end="")
try:
fh = open("db/boughts", "a")
except IOError:
sys.exit("Failed to open the database file");
post = cgi.FieldStorage()
boughts = json.loads(post["data"].value);
method = "B" if post["method"].value == "1" else "C" if post["method"].value == "2" else "S"
nowdt = datetime.datetime.now()
nowtuple = nowdt.timetuple()
nowtimestamp = time.mktime(nowtuple)
date = utils.formatdate(nowtimestamp)
ip = os.environ["REMOTE_ADDR"]
printstr = ""
for bought in boughts:
product = html.unescape(bought["product"]);
fh.write(date + "\t" + ip + "\t" + str(bought["price"]) + "\t" + method + "\t" + product + "\n")
price = "{:6.2f}".format(bought["price"]).replace(".", ",")
printstr += (nowdt.strftime("%d.%m. %H:%M:%S") + " " + price + " € " + method + " " + product)[:44] + "\n"
fh.close()
#s = open("/dev/ttyUSB0", "wb")
#s.write(b"\x1b\x52\x06") # cp858
#def printout(st):
# s.write(st.encode("cp858"))
# s.flush()
#printout(printstr)
print("OK",end="")