works now but prints weird
This commit is contained in:
parent
8e87c75c3a
commit
f8fa50c223
22
addtoDB.py
22
addtoDB.py
@ -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
|
||||
|
||||
|
114
carousel.py
114
carousel.py
@ -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
|
||||
@ -228,7 +235,7 @@ while True:
|
||||
except:
|
||||
print('traceback.format_exc():\n%s' % traceback.format_exc())
|
||||
exit()
|
||||
|
||||
|
||||
#create half-size bmps for cycling through
|
||||
half1 = Image.open(jpgpath1)
|
||||
half2 = Image.open(jpgpath2)
|
||||
@ -243,11 +250,11 @@ while True:
|
||||
half2.save(bmpath2)
|
||||
half3 = half3.convert("1")
|
||||
half3.save(bmpath3)
|
||||
|
||||
|
||||
|
||||
## CREATE screen image to display:
|
||||
|
||||
|
||||
|
||||
|
||||
## CREATE screen image to display:
|
||||
|
||||
# create quarter sized bmps
|
||||
im1 = Image.open(jpgpath1)
|
||||
im2 = Image.open(jpgpath2)
|
||||
@ -256,7 +263,7 @@ while True:
|
||||
im1 = im1.resize(newsize)
|
||||
im2 = im2.resize(newsize)
|
||||
im3 = im3.resize(newsize)
|
||||
|
||||
|
||||
#add quarter sized photos and instructions to the image to be rendered
|
||||
instructions = imagesPath + 'instructions.bmp'
|
||||
im4 = Image.open(instructions)
|
||||
@ -264,8 +271,8 @@ while True:
|
||||
Limage.paste(im2, (150,0))
|
||||
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)
|
||||
@ -275,13 +282,13 @@ while True:
|
||||
# draw.text((152, 280), 'button 3: retake', font = font18, fill = 255)
|
||||
# draw.text((152, 00), 'buttons 4 or 5:', font = font18, fill = 255)
|
||||
# draw.text((152, 640), 'exit photo mode', font = font18, fill = 255)
|
||||
|
||||
|
||||
# display the image
|
||||
epd.init()
|
||||
epd.display(epd.getbuffer(Limage))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#pulse LED while we wait for user to press something
|
||||
button_flag = "none"
|
||||
while button_flag == "none":
|
||||
@ -296,46 +303,50 @@ while True:
|
||||
|
||||
#led to thinking mode
|
||||
buttonshim.set_pixel(0x00, 0x00, 0xFF)
|
||||
|
||||
|
||||
|
||||
|
||||
# if we're printing, generate image to print
|
||||
if button_flag == "button_1" or button_flag == "button_2" or button_flag == "button_3":
|
||||
#generate unique file_name
|
||||
unique = uuid.uuid4()
|
||||
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)
|
||||
im2 = Image.open(jpgpath2)
|
||||
im3 = Image.open(jpgpath3)
|
||||
|
||||
|
||||
get_concat_v(header, im1).save(composite)
|
||||
concaz = Image.open(composite)
|
||||
get_concat_v(concaz, im2).save(composite)
|
||||
concaz = Image.open(composite)
|
||||
get_concat_v(concaz, im3).save(composite)
|
||||
get_concat_v(concaz, im3).save(composite)
|
||||
concaz = Image.open(composite)
|
||||
|
||||
|
||||
|
||||
#post to ssb and print
|
||||
if button_flag == "button_1":
|
||||
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,35 +354,36 @@ 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
|
||||
unique = uuid.uuid4()
|
||||
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()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#update dbCount
|
||||
for item in db:
|
||||
dbCount = item.doc_id
|
||||
@ -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))
|
||||
|
||||
|
||||
@ -416,7 +428,7 @@ while True:
|
||||
button_flag == "null"
|
||||
#nothin! loop around... exitPhotoMode still false
|
||||
|
||||
|
||||
|
||||
|
||||
#reshoot
|
||||
if (button_flag == "button_4"):
|
||||
@ -424,7 +436,7 @@ while True:
|
||||
exitPhotoMode = True
|
||||
os.remove(bmpath)
|
||||
os.remove(jpgpath)
|
||||
|
||||
|
||||
#exit photo mode
|
||||
if (button_flag == "button_5"):
|
||||
button_flag == "null"
|
||||
|
@ -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)]"
|
||||
|
Loading…
Reference in New Issue
Block a user