backup while laptop is on the fritz
This commit is contained in:
parent
8abb5bc2ee
commit
383cad8808
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,6 +1,11 @@
|
||||
freeze_frame.jpg
|
||||
\freeze_frame.jpg
|
||||
qr.jpg
|
||||
users.json
|
||||
merged_image.jpg
|
||||
drawing.png
|
||||
to_print.zpl
|
||||
tmp/*
|
||||
merged_image.png
|
||||
__pycache__/*
|
||||
freeze_frame.png
|
||||
image-temp.jpg
|
||||
|
Binary file not shown.
Binary file not shown.
46
addtoDB.py
46
addtoDB.py
@ -9,7 +9,7 @@ import traceback
|
||||
import os, sys
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
def main():
|
||||
@ -26,7 +26,6 @@ def main():
|
||||
exit(1)
|
||||
|
||||
|
||||
|
||||
def addToSSB(pathToImage,description,mintOrGive):
|
||||
|
||||
# mint
|
||||
@ -68,5 +67,48 @@ def addToSSB(pathToImage,description,mintOrGive):
|
||||
return key
|
||||
|
||||
|
||||
def get_message_content(message_id):
|
||||
try:
|
||||
print(f"Executing command: ./ssb-post.sh get_message_content {message_id}")
|
||||
result = subprocess.run(['./ssb-post.sh', 'get_message_content', message_id],
|
||||
capture_output=True, text=True, check=True)
|
||||
|
||||
print(f"Command output:\n{result.stdout}")
|
||||
|
||||
# Split the output into lines
|
||||
lines = result.stdout.split('\n')
|
||||
|
||||
# Extract the image path
|
||||
image_path = None
|
||||
for line in lines:
|
||||
if line.startswith("IMAGE_PATH:"):
|
||||
image_path = line.split(":", 1)[1].strip()
|
||||
break
|
||||
|
||||
# Find the start of the JSON content
|
||||
json_start = next(i for i, line in enumerate(lines) if line.strip().startswith("{"))
|
||||
|
||||
# Join the JSON lines and parse
|
||||
json_content = "\n".join(lines[json_start:])
|
||||
message_content = json.loads(json_content)
|
||||
|
||||
print(f"Parsed message content: {message_content}")
|
||||
print(f"Image path: {image_path}")
|
||||
|
||||
return message_content, image_path
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error: subprocess.CalledProcessError - {e}")
|
||||
print(f"Debug: stdout = {e.stdout}")
|
||||
print(f"Debug: stderr = {e.stderr}")
|
||||
return None, None
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"Error: json.JSONDecodeError - {e}")
|
||||
print(f"Debug: stdout = {result.stdout}")
|
||||
return None, None
|
||||
except Exception as e:
|
||||
print(f"Error: Unexpected exception - {e}")
|
||||
return None, None
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
BIN
freeze_frame.jpg
BIN
freeze_frame.jpg
Binary file not shown.
Before Width: | Height: | Size: 29 KiB |
@ -533,8 +533,14 @@ class Screen5(tk.Frame):
|
||||
# Saving the text from the entry field to a global variable
|
||||
global info_text
|
||||
info_text = self.info_entry.get("1.0", "end-1c")
|
||||
# test
|
||||
# print(info_text)
|
||||
# escape the newlines!:
|
||||
info_text = info_text.replace('\n', '\\n')
|
||||
# print(info_text)
|
||||
# escape quotes as well:
|
||||
# info_text = info_text.replace('"', '\\"')
|
||||
# print(info_text)
|
||||
self.master.switch_frame(Screen11)
|
||||
|
||||
# I understand
|
||||
@ -801,6 +807,10 @@ class Screen13(tk.Frame):
|
||||
# ssb give! (make sure we have a UID to give to first)
|
||||
if GlobalVars.selected_user and GlobalVars.selected_user.strip() != "":
|
||||
nothing = addtoDB.addToSSB(GlobalVars.selected_user,key,2)
|
||||
|
||||
# gonna need to revise this later but for now the textile tags are always full-size QR:
|
||||
if print_type == "ribbon":
|
||||
QRscale = 7
|
||||
|
||||
# Create qr code
|
||||
#from https://ourcodeworld.com/articles/read/554/how-to-create-a-qr-code-image-or-svg-in-python
|
||||
@ -840,7 +850,7 @@ class Screen13(tk.Frame):
|
||||
if print_type == "ribbon":
|
||||
merged_image = Image.new('L', (375, 675), "white")
|
||||
merged_image.paste(drawing, (25, 100)) # set it 25 in because that's the border
|
||||
merged_image.paste(qr, (25, 279)) # paste without mask
|
||||
merged_image.paste(qr, (42, 279)) # paste without mask
|
||||
merged_image.save("merged_image.png")
|
||||
image = Image.open("merged_image.png")
|
||||
# rotated_image = image.transpose(Image.ROTATE_270) # Transpose and rotate 90 degrees, old version when we weren't doing ribbon vertical
|
||||
@ -863,6 +873,7 @@ class Screen13(tk.Frame):
|
||||
if print_type == "sticker":
|
||||
try:
|
||||
result = subprocess.Popen('lpr -P sticker_printer -o raw to_print.zpl', shell=True, stdout=subprocess.PIPE, )
|
||||
# print('no print')
|
||||
except:
|
||||
print('traceback.format_exc():\n%s' % traceback.format_exc())
|
||||
exit()
|
26
ssb-custodisco-plugin.js
Normal file
26
ssb-custodisco-plugin.js
Normal file
@ -0,0 +1,26 @@
|
||||
const ssbClient = require('ssb-client')
|
||||
|
||||
module.exports = {
|
||||
name: 'custodisco',
|
||||
version: '1.0.0',
|
||||
manifest: {
|
||||
getItem: 'async'
|
||||
},
|
||||
init: (server, config) => {
|
||||
return {
|
||||
getItem: async (id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
ssbClient((err, sbot) => {
|
||||
if (err) return reject(err)
|
||||
|
||||
sbot.get(id, (err, value) => {
|
||||
sbot.close()
|
||||
if (err) return reject(err)
|
||||
resolve(value)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
79
ssb-post.sh
79
ssb-post.sh
@ -65,3 +65,82 @@ BLAAB
|
||||
fi
|
||||
|
||||
|
||||
## get_message_content
|
||||
if [ "$1" == "get_message_content" ]
|
||||
then
|
||||
messageID=$2
|
||||
|
||||
echo "Attempting to retrieve message: $messageID" >&2
|
||||
|
||||
# Get message content
|
||||
message_content=$(ssb-server get "$messageID" 2>&1)
|
||||
|
||||
# Check if ssb-server get was successful
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: ssb-server get failed" >&2
|
||||
echo "$message_content" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Successfully retrieved message content" >&2
|
||||
|
||||
# Extract blob information
|
||||
blobs=$(echo "$message_content" | jq -r '.content.mentions[] | select(.link | startswith("&")) | .link')
|
||||
|
||||
# Process blobs
|
||||
if [ -n "$blobs" ]; then
|
||||
echo "Processing blobs..." >&2
|
||||
echo "$message_content" | jq -c '.content.mentions[]' | while read -r mention; do
|
||||
blob=$(echo "$mention" | jq -r '.link')
|
||||
if [[ "$blob" == \&* ]]; then
|
||||
echo "Found a blob: $blob" >&2
|
||||
# First, try to get the mime type from the message content
|
||||
mime_type=$(echo "$mention" | jq -r '.type')
|
||||
|
||||
# If mime type is not in the message content, try to get it from blobs.meta
|
||||
if [[ "$mime_type" == "null" || -z "$mime_type" ]]; then
|
||||
if ssb-server blobs.has "$blob"; then
|
||||
mime_type=$(ssb-server blobs.meta "$blob" | jq -r '.type')
|
||||
else
|
||||
echo "Blob not available locally: $blob" >&2
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Blob mime type: $mime_type" >&2
|
||||
|
||||
if [[ "$mime_type" == "image/jpeg" || "$mime_type" == "image/png" ]]; then
|
||||
# Create tmp directory if it doesn't exist
|
||||
mkdir -p tmp
|
||||
|
||||
# Get blob and save it to a file
|
||||
file_extension="${mime_type#image/}"
|
||||
short_name=$(echo "$blob" | md5sum | cut -d' ' -f1)
|
||||
file_name="${short_name}.$file_extension"
|
||||
full_path="tmp/$file_name"
|
||||
|
||||
echo "Attempting to save blob to: $full_path" >&2
|
||||
echo "Executing command: ssb-server blobs.get $blob > $full_path" >&2
|
||||
|
||||
if ssb-server blobs.get "$blob" > "$full_path" 2>/dev/null; then
|
||||
echo "Blob saved: $full_path" >&2
|
||||
echo "IMAGE_PATH:$full_path"
|
||||
else
|
||||
echo "Failed to retrieve blob: $blob" >&2
|
||||
echo "ssb-server blobs.get exit code: $?" >&2
|
||||
# If the file wasn't created, let's try to output the blob data directly
|
||||
echo "Attempting to output blob data directly:" >&2
|
||||
ssb-server blobs.get "$blob" | head -c 100 | xxd >&2
|
||||
fi
|
||||
else
|
||||
echo "Skipping non-image blob: $blob (type: $mime_type)" >&2
|
||||
fi
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "No blobs found in the message." >&2
|
||||
fi
|
||||
|
||||
# Output message content
|
||||
echo "$message_content"
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user