/
print_shopping.py
46 lines (36 loc) · 1002 Bytes
/
print_shopping.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/python
import time
import json
import glob
import os
from gpiozero import Button
from Adafruit_Thermal import *
button = Button(12)
printer = Adafruit_Thermal("/dev/ttyUSB0", 9600, timeout=5)
while True:
if button.is_pressed:
#any new json files?
new_files = sorted(glob.glob('/home/pi/jsonin/*'))
if new_files:
#open and reload the data
with open('/home/pi/jsonin/alldata.json') as json_data:
d = json.load(json_data)
#os.remove(new_files[0])
shopping_list = []
f = open("/dev/ttyUSB0", "w")
category = 0
for i in d["shopping"]:
if i["category_id"] != category:
printer.feed(1)
printer.setSize('M')
printer.boldOn()
printer.underlineOn()
printer.println(i["category"])
printer.boldOff()
printer.underlineOff()
printer.setSize('S')
printer.println(i["item"])
category = i["category_id"]
shopping_list.append(i["item"])
f.write ("\n\n\n")
f.close()