works now but prints weird
This commit is contained in:
parent
8e87c75c3a
commit
f8fa50c223
18
addtoDB.py
18
addtoDB.py
@ -7,6 +7,7 @@ import optparse
|
|||||||
import iterparse
|
import iterparse
|
||||||
import traceback
|
import traceback
|
||||||
import os, sys
|
import os, sys
|
||||||
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
from tinydb import TinyDB, Query
|
from tinydb import TinyDB, Query
|
||||||
|
|
||||||
@ -26,22 +27,25 @@ def main():
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def addToDB(pathToImage, pathToDB,composite):
|
||||||
|
|
||||||
def addFile(pathToImage, pathToDB, SSBidentify, composite):
|
|
||||||
#init db
|
#init db
|
||||||
db = TinyDB(pathToDB)
|
db = TinyDB(pathToDB)
|
||||||
|
|
||||||
#add to db
|
#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("all done, added to db")
|
||||||
#print("heres the whole db")
|
#print("heres the whole db")
|
||||||
#print(db.all())
|
#print(db.all())
|
||||||
|
|
||||||
|
|
||||||
|
def addToSSB(pathToImage, pathToDB, SSBidentify):
|
||||||
|
|
||||||
#unless you say don't post to ssb, post to ssb
|
#unless you say don't post to ssb, post to ssb
|
||||||
if SSBidentify != -1:
|
if SSBidentify != -1:
|
||||||
#SEND TO SSB! WOOOO
|
#SEND TO SSB! WOOOO
|
||||||
try:
|
try:
|
||||||
result = subprocess.call('./ssbpost.sh ' + pathToImage, shell=True)
|
result = subprocess.Popen('./ssbpost.sh ' + pathToImage, shell=True, stdout=subprocess.PIPE, )
|
||||||
except:
|
except:
|
||||||
print('traceback.format_exc():\n%s' % traceback.format_exc())
|
print('traceback.format_exc():\n%s' % traceback.format_exc())
|
||||||
exit()
|
exit()
|
||||||
@ -49,12 +53,12 @@ def addFile(pathToImage, pathToDB, SSBidentify, composite):
|
|||||||
|
|
||||||
# get the ssb json from the bash command we just ran
|
# get the ssb json from the bash command we just ran
|
||||||
newssb=result.stdout.read()
|
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
|
# get the key for the post we just made
|
||||||
key = decoded['key']
|
key = json_object["key"]
|
||||||
|
|
||||||
|
|
||||||
return key
|
return key
|
||||||
|
|
||||||
|
40
carousel.py
40
carousel.py
@ -124,6 +124,13 @@ def get_concat_h(im1, im2):
|
|||||||
dst.paste(im2, (im1.width, 0))
|
dst.paste(im2, (im1.width, 0))
|
||||||
return dst
|
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 ##
|
## MAIN LOOP ##
|
||||||
while True:
|
while True:
|
||||||
# chill for a bit, keep track of how long we're chilling
|
# chill for a bit, keep track of how long we're chilling
|
||||||
@ -325,9 +332,13 @@ while True:
|
|||||||
button_flag == "null"
|
button_flag == "null"
|
||||||
|
|
||||||
|
|
||||||
#add the photo to the db/ssb
|
#add each photo to the db
|
||||||
key = addtoDB.addFile(bmpath,dbPath,0,composite)
|
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
|
# Create qr code
|
||||||
@ -335,7 +346,7 @@ while True:
|
|||||||
qr = qrcode.QRCode(
|
qr = qrcode.QRCode(
|
||||||
version = 1,
|
version = 1,
|
||||||
error_correction = qrcode.constants.ERROR_CORRECT_H,
|
error_correction = qrcode.constants.ERROR_CORRECT_H,
|
||||||
box_size = 4,
|
box_size = 5,
|
||||||
border = 1,
|
border = 1,
|
||||||
)
|
)
|
||||||
# Add data
|
# Add data
|
||||||
@ -343,16 +354,16 @@ while True:
|
|||||||
qr.make(fit=True)
|
qr.make(fit=True)
|
||||||
# Create an image from the QR Code instance
|
# Create an image from the QR Code instance
|
||||||
img = qr.make_image()
|
img = qr.make_image()
|
||||||
|
whereToSaveQR = imagesPath + 'QR.jpg'
|
||||||
|
img.save(whereToSaveQR)
|
||||||
|
|
||||||
|
|
||||||
# concatenate QR instructions with QR
|
# concatenate QR instructions with QR
|
||||||
whereQRinstructionsAre = imagesPath + 'ssbqrinstgurct.bmp'
|
whereQRinstructionsAre = imagesPath + 'ssbqrinstgurct.jpg'
|
||||||
qrInstruct = Image.open(whereQRinstructionsAre)
|
qrInstruct = Image.open(whereQRinstructionsAre)
|
||||||
|
whereInstructionsPlusQRis = imagesPath + 'instructionsPlusQR.jpg'
|
||||||
|
get_concat_h_blank(qrInstruct, img, (255, 255, 255)).save(whereInstructionsPlusQRis)
|
||||||
|
instr = Image.open(whereInstructionsPlusQRis)
|
||||||
# concatenate QR+instructions to full composite for print
|
|
||||||
|
|
||||||
|
|
||||||
#generate unique file_name
|
#generate unique file_name
|
||||||
@ -360,11 +371,12 @@ while True:
|
|||||||
unique = str(unique)
|
unique = str(unique)
|
||||||
FULLcomposite = imagesPath + unique + '.jpg'
|
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
|
# print Fullcomposite
|
||||||
try:
|
try:
|
||||||
result = subprocess.call('lp' + Fullcomposite, shell=True)
|
result = subprocess.call('lp ' + FULLcomposite, shell=True)
|
||||||
except:
|
except:
|
||||||
print('traceback.format_exc():\n%s' % traceback.format_exc())
|
print('traceback.format_exc():\n%s' % traceback.format_exc())
|
||||||
exit()
|
exit()
|
||||||
@ -379,11 +391,11 @@ while True:
|
|||||||
|
|
||||||
#display the image to clear the menu (also display text "posted")
|
#display the image to clear the menu (also display text "posted")
|
||||||
font18 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 24)
|
font18 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 24)
|
||||||
bmp = Image.open(bmpath)
|
bmp = Image.open(bmpath1)
|
||||||
Limage.paste(bmp)
|
Limage.paste(bmp)
|
||||||
draw = ImageDraw.Draw(Limage)
|
draw = ImageDraw.Draw(Limage)
|
||||||
draw.text((2, 240), 'PHOTO POSTED', font = font18, fill = 255)
|
draw.text((2, 240), 'photostrip posted', font = font18, fill = 255)
|
||||||
draw.text((2, 260), 'online!', font = font18, fill = 255)
|
draw.text((2, 260), 'to SSB', font = font18, fill = 255)
|
||||||
epd.display(epd.getbuffer(Limage))
|
epd.display(epd.getbuffer(Limage))
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#add blob
|
#add blob
|
||||||
blobID=$(cat $1 | ssb-server blobs.add)
|
blobID=$(cat $1 | ssb-server blobs.add)
|
||||||
|
|
||||||
echo $blobID
|
#echo $blobID
|
||||||
|
|
||||||
#publish blob
|
#publish blob
|
||||||
#key=$(ssb-server publish --type post --text "![upload.bmp($blobID)]"
|
#key=$(ssb-server publish --type post --text "![upload.bmp($blobID)]"
|
||||||
|
Loading…
Reference in New Issue
Block a user