works now but prints weird

This commit is contained in:
trav 2022-08-17 15:39:36 -04:00
parent 8e87c75c3a
commit f8fa50c223
3 changed files with 77 additions and 61 deletions

View File

@ -7,6 +7,7 @@ import optparse
import iterparse
import traceback
import os, sys
import json
import subprocess
from tinydb import TinyDB, Query
@ -26,22 +27,25 @@ def main():
exit(1)
def addToDB(pathToImage, pathToDB,composite):
def addFile(pathToImage, pathToDB, SSBidentify, composite):
#init db
#init db
db = TinyDB(pathToDB)
#add to db
db.insert({'path': pathToImage, 'date': 4, 'ssb': SSBidentify, 'composite': composite})
db.insert({'path': pathToImage, 'date': 4, 'ssb': '-2', 'composite': composite})
print("all done, added to db")
#print("heres the whole db")
#print(db.all())
def addToSSB(pathToImage, pathToDB, SSBidentify):
#unless you say don't post to ssb, post to ssb
if SSBidentify != -1:
#SEND TO SSB! WOOOO
try:
result = subprocess.call('./ssbpost.sh ' + pathToImage, shell=True)
result = subprocess.Popen('./ssbpost.sh ' + pathToImage, shell=True, stdout=subprocess.PIPE, )
except:
print('traceback.format_exc():\n%s' % traceback.format_exc())
exit()
@ -49,12 +53,12 @@ def addFile(pathToImage, pathToDB, SSBidentify, composite):
# get the ssb json from the bash command we just ran
newssb=result.stdout.read()
print(newssb)
#convert string to object
json_object = json.loads(newssb)
# iterate through new ssb posts
for decoded in iterparse.parsy(newssb):
# get the key for the post we just made
key = decoded['key']
# get the key for the post we just made
key = json_object["key"]
return key

View File

@ -124,6 +124,13 @@ def get_concat_h(im1, im2):
dst.paste(im2, (im1.width, 0))
return dst
def get_concat_h_blank(im1, im2, color=(0, 0, 0)):
dst = Image.new('RGB', (im1.width + im2.width, max(im1.height, im2.height)), color)
dst.paste(im1, (0, 0))
dst.paste(im2, (im1.width, 0))
return dst
## MAIN LOOP ##
while True:
# chill for a bit, keep track of how long we're chilling
@ -265,7 +272,7 @@ while True:
Limage.paste(im3, (0,200))
Limage.paste(im4, (150,200))
#add the menu
#add the menu
# draw = ImageDraw.Draw(Limage)
# font18 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 10)
# draw.text((152, 200), 'press button 1 to:', font = font18, fill = 255)
@ -305,7 +312,7 @@ while True:
unique = str(unique)
composite = imagesPath + unique + '.jpg'
# concatenate images and save concatenated image at composite (is filepath)
# concatenate images and save concatenated image at composite (is filepath)
headerIsAt = imagesPath + 'header.jpg'
header = Image.open(headerIsAt)
im1 = Image.open(jpgpath1)
@ -325,17 +332,21 @@ while True:
button_flag == "null"
#add the photo to the db/ssb
key = addtoDB.addFile(bmpath,dbPath,0,composite)
#add each photo to the db
addtoDB.addToDB(bmpath1,dbPath,composite)
addtoDB.addToDB(bmpath2,dbPath,composite)
addtoDB.addToDB(bmpath3,dbPath,composite)
#add the photo strip to the ssb
key = addtoDB.addToSSB(composite,dbPath,0)
# Create qr code
#from https://ourcodeworld.com/articles/read/554/how-to-create-a-qr-code-image-or-svg-in-python
#from https://ourcodeworld.com/articles/read/554/how-to-create-a-qr-code-image-or-svg-in-python
qr = qrcode.QRCode(
version = 1,
error_correction = qrcode.constants.ERROR_CORRECT_H,
box_size = 4,
box_size = 5,
border = 1,
)
# Add data
@ -343,16 +354,16 @@ while True:
qr.make(fit=True)
# Create an image from the QR Code instance
img = qr.make_image()
whereToSaveQR = imagesPath + 'QR.jpg'
img.save(whereToSaveQR)
# concatenate QR instructions with QR
whereQRinstructionsAre = imagesPath + 'ssbqrinstgurct.bmp'
whereQRinstructionsAre = imagesPath + 'ssbqrinstgurct.jpg'
qrInstruct = Image.open(whereQRinstructionsAre)
# concatenate QR+instructions to full composite for print
whereInstructionsPlusQRis = imagesPath + 'instructionsPlusQR.jpg'
get_concat_h_blank(qrInstruct, img, (255, 255, 255)).save(whereInstructionsPlusQRis)
instr = Image.open(whereInstructionsPlusQRis)
#generate unique file_name
@ -360,11 +371,12 @@ while True:
unique = str(unique)
FULLcomposite = imagesPath + unique + '.jpg'
get_concat_v(concaz, (get_concat_h(qrInstruct, img))).save(FULLcomposite)
# concatenate existing composite image with the instructions+QR composite for full composite image for print
get_concat_v(concaz, instr).save(FULLcomposite)
# print Fullcomposite
try:
result = subprocess.call('lp' + Fullcomposite, shell=True)
result = subprocess.call('lp ' + FULLcomposite, shell=True)
except:
print('traceback.format_exc():\n%s' % traceback.format_exc())
exit()
@ -379,11 +391,11 @@ while True:
#display the image to clear the menu (also display text "posted")
font18 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 24)
bmp = Image.open(bmpath)
bmp = Image.open(bmpath1)
Limage.paste(bmp)
draw = ImageDraw.Draw(Limage)
draw.text((2, 240), 'PHOTO POSTED', font = font18, fill = 255)
draw.text((2, 260), 'online!', font = font18, fill = 255)
draw.text((2, 240), 'photostrip posted', font = font18, fill = 255)
draw.text((2, 260), 'to SSB', font = font18, fill = 255)
epd.display(epd.getbuffer(Limage))

View File

@ -5,7 +5,7 @@
#add blob
blobID=$(cat $1 | ssb-server blobs.add)
echo $blobID
#echo $blobID
#publish blob
#key=$(ssb-server publish --type post --text "![upload.bmp($blobID)]"