PLEASE TRY
This commit is contained in:
parent
c39c4b8936
commit
f614643a70
|
@ -0,0 +1,100 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import argparse
|
||||
|
||||
from PIL import Image, ImageFont, ImageDraw
|
||||
from font_hanken_grotesk import HankenGroteskBold, HankenGroteskMedium
|
||||
from font_intuitive import Intuitive
|
||||
from inky import InkyPHAT, InkyWHAT
|
||||
|
||||
print("""Inky pHAT/wHAT: Hello... my name is:
|
||||
|
||||
Use Inky pHAT/wHAT as a personalised name badge!
|
||||
|
||||
""")
|
||||
|
||||
# Command line arguments to set display type and colour, and enter your name
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--type', '-t', type=str, required=True, choices=["what", "phat"], help="type of display")
|
||||
parser.add_argument('--colour', '-c', type=str, required=True, choices=["red", "black", "yellow"], help="ePaper display colour")
|
||||
parser.add_argument('--name', '-n', type=str, required=True, help="Your name")
|
||||
parser.add_argument('--madate', '-d', type=str, required=True, help="Date")
|
||||
args = parser.parse_args()
|
||||
|
||||
colour = args.colour
|
||||
|
||||
# Set up the correct display and scaling factors
|
||||
|
||||
if args.type == "phat":
|
||||
inky_display = InkyPHAT(colour)
|
||||
scale_size = 1
|
||||
padding = 0
|
||||
elif args.type == "what":
|
||||
inky_display = InkyWHAT(colour)
|
||||
scale_size = 2.20
|
||||
padding = 15
|
||||
|
||||
# inky_display.set_rotation(180)
|
||||
inky_display.set_border(inky_display.RED)
|
||||
|
||||
# Create a new canvas to draw on
|
||||
|
||||
img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
# Load the fonts
|
||||
|
||||
intuitive_font = ImageFont.truetype(Intuitive, int(22 * scale_size))
|
||||
hanken_bold_font = ImageFont.truetype(HankenGroteskBold, int(35 * scale_size))
|
||||
hanken_medium_font = ImageFont.truetype(HankenGroteskMedium, int(16 * scale_size))
|
||||
|
||||
# Grab the name to be displayed
|
||||
|
||||
name = args.name
|
||||
madate = args.madate
|
||||
|
||||
# Top and bottom y-coordinates for the white strip
|
||||
|
||||
y_top = int(inky_display.HEIGHT * (5.0 / 10.0))
|
||||
y_bottom = y_top + int(inky_display.HEIGHT * (4.0 / 10.0))
|
||||
|
||||
# Draw the red, white, and red strips
|
||||
|
||||
for y in range(0, y_top):
|
||||
for x in range(0, inky_display.width):
|
||||
img.putpixel((x, y), inky_display.RED)
|
||||
|
||||
for y in range(y_top, y_bottom):
|
||||
for x in range(0, inky_display.width):
|
||||
img.putpixel((x, y), inky_display.WHITE)
|
||||
|
||||
for y in range(y_bottom, inky_display.HEIGHT):
|
||||
for x in range(0, inky_display.width):
|
||||
img.putpixel((x, y), inky_display.RED)
|
||||
|
||||
# Calculate the positioning and draw the name text
|
||||
|
||||
hello_w, hello_h = hanken_bold_font.getsize(name)
|
||||
hello_x = int((inky_display.WIDTH - hello_w) / 2)
|
||||
hello_y = 0 + padding
|
||||
draw.text((hello_x, hello_y), name, inky_display.WHITE, font=hanken_bold_font)
|
||||
|
||||
# Calculate the positioning and draw the madate text
|
||||
|
||||
mynameis_w, mynameis_h = hanken_medium_font.getsize("membres de la G1")
|
||||
mynameis_x = int((inky_display.WIDTH - mynameis_w) / 2)
|
||||
mynameis_y = hello_h + padding
|
||||
draw.text((mynameis_x, mynameis_y), "membres de la G1", inky_display.WHITE, font=hanken_medium_font)
|
||||
|
||||
# Calculate the positioning and draw the "nombre de membres" text
|
||||
|
||||
name_w, name_h = intuitive_font.getsize(madate)
|
||||
name_x = int((inky_display.WIDTH - name_w) / 2)
|
||||
name_y = int(y_top + ((y_bottom - y_top - name_h) / 2))
|
||||
draw.text((name_x, name_y), madate, inky_display.BLACK, font=intuitive_font)
|
||||
|
||||
# Display the completed name badge
|
||||
|
||||
inky_display.set_image(img)
|
||||
inky_display.show()
|
|
@ -0,0 +1,112 @@
|
|||
#!/bin/bash
|
||||
################################################################################
|
||||
# Author: Fred (support@qo-op.com)
|
||||
# Version: 0.1
|
||||
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
||||
################################################################################
|
||||
# SCAN & DISPLAY G1 MEMBERS
|
||||
################################################################################
|
||||
DUNITER="https://g1.le-sou.org"
|
||||
CESIUM="https://g1.data.le-sou.org"
|
||||
|
||||
# TEST INTERNET CONNEXION
|
||||
ip="$(ifconfig wlan0 | grep "inet " | awk '{print $2}')"
|
||||
|
||||
if [[ "$ip" != "" ]]; then
|
||||
curl ${DUNITER}/wot/members > "./members.json"
|
||||
total=$(cat "./members.json" | jq '.results' | jq length)
|
||||
# DISPLAY Startup Screen
|
||||
python ./name-badge.py --type phat --colour black --name $total --madate "$ip"
|
||||
else
|
||||
ssid=$(sudo cat /etc/wpa_supplicant/wpa_supplicant.conf | grep "ssid=\"")
|
||||
python ./name-badge.py --type phat --colour black --name "NO INTERNET" --madate "$ssid"
|
||||
# DISPLAY ALL already collected members...
|
||||
for inky in $(ls ./SCAN/*/inky.png); do cp "$inky" "./result.png"; python inky_display.py; sleep 10; done
|
||||
sudo reboot
|
||||
fi
|
||||
|
||||
echo "$total membres"
|
||||
|
||||
# Forever Loop
|
||||
while :
|
||||
do
|
||||
# Selection d'un autre membre au hasard
|
||||
numero=$((RANDOM % $total))
|
||||
member=$(($numero - 1))
|
||||
|
||||
# Récupération de son uid et pubkey
|
||||
MEMBER=$(cat "./members.json" | jq ".results[$member].uid" | sed s/\"//g)
|
||||
PUBKEY=$(cat "./members.json" | jq ".results[$member].pubkey" | sed s/\"//g)
|
||||
|
||||
# MAKES ALL MEMBERS QUICKER COLLECTED
|
||||
#if [[ -d "./SCAN/${PUBKEY}" ]]; then continue; fi
|
||||
|
||||
mkdir -p "./SCAN/${PUBKEY}"
|
||||
# silkaj : Record uid / history / amount
|
||||
echo ${MEMBER} > "./SCAN/${PUBKEY}/uid.txt" # uid
|
||||
silkaj history ${PUBKEY} > "./SCAN/${PUBKEY}/history.txt" # history
|
||||
usage=$(cat "./SCAN/${PUBKEY}/history.txt" | wc -l)
|
||||
amount=$(cat "./SCAN/${PUBKEY}/history.txt" | grep balance | cut -d ":" -f 2 | cut -d "," -f 1 | xargs)
|
||||
|
||||
echo $amount > "./SCAN/${PUBKEY}/amount.txt" # amount
|
||||
g1=$(echo $amount | cut -d '.' -f 1)
|
||||
love=$(echo $amount | awk '{print $1 * 100}')
|
||||
|
||||
echo $amount > "./SCAN/${PUBKEY}/g1.txt" # g1
|
||||
|
||||
# RECORD MEMBER DATA
|
||||
echo "${MEMBER} : $amount ($usage) ${PUBKEY}"
|
||||
if [[ "$love" != "" ]]; then
|
||||
curl ${CESIUM}/user/profile/${PUBKEY} > "./tmp/${PUBKEY}"
|
||||
|
||||
mkdir -p "./IPFS/MEMBERS/${MEMBER}/WALLETS/member.${PUBKEY}"
|
||||
echo "$g1" > "./IPFS/MEMBERS/${usage}.${MEMBER}"
|
||||
|
||||
mkdir -p "./IPFS/WALLETS/${PUBKEY}/in"
|
||||
mkdir -p "./IPFS/WALLETS/${PUBKEY}/out"
|
||||
echo "$love" > "./IPFS/WALLETS/${PUBKEY}/LOVE"
|
||||
|
||||
|
||||
# Write Member details
|
||||
cat "./tmp/${PUBKEY}" | jq '._source.socials' > "./IPFS/MEMBERS/${MEMBER}/social.json"
|
||||
cat "./tmp/${PUBKEY}" | jq '._source.title' > "./IPFS/MEMBERS/${MEMBER}/adressse.json"
|
||||
cat "./tmp/${PUBKEY}" | jq '._source.address' >> "./IPFS/MEMBERS/${MEMBER}/adressse.json"
|
||||
cat "./tmp/${PUBKEY}" | jq '._source.city' >> "./IPFS/MEMBERS/${MEMBER}/adressse.json"
|
||||
cat "./tmp/${PUBKEY}" | jq '._source.description' > "./IPFS/MEMBERS/${MEMBER}/description.json"
|
||||
cat "./tmp/${PUBKEY}" | jq '._source.geoPoint' > "./IPFS/MEMBERS/${MEMBER}/geoPoint.json"
|
||||
|
||||
cat "./IPFS/MEMBERS/${MEMBER}/social.json"
|
||||
fi
|
||||
|
||||
|
||||
# Téléchargement de la photo Cesium+?
|
||||
test=$(curl ${CESIUM}/user/profile/${PUBKEY} | jq '._source.avatar._content')
|
||||
if [[ $test != null ]]; then
|
||||
# GET avatar.png, rotate, put over in G1.png, write member name, 3 color then display
|
||||
|
||||
curl ${CESIUM}/user/profile/${PUBKEY} | jq '._source.avatar._content' | sed 's/\"//g' | base64 -d > "./SCAN/${PUBKEY}/avatar.png"
|
||||
|
||||
convert "./SCAN/${PUBKEY}/avatar.png" -rotate 90 "./tmp/rotate.png"
|
||||
composite -compose Over -gravity East "./tmp/rotate.png" "./G1.png" "/tmp/image0.png"
|
||||
|
||||
qrencode -s 3 -o "./tmp/PUBKEY.png" ${PUBKEY}
|
||||
composite -compose Over -gravity West "./tmp/PUBKEY.png" "/tmp/image0.png" "./tmp/image.png"
|
||||
|
||||
convert -font 'Times-Bold' -pointsize 20 -fill black -draw 'text 100,20 "'"${MEMBER}"'"' "./tmp/image.png" "./tmp/uid.png"
|
||||
|
||||
else
|
||||
# CREATE PUBKEY put over in G1.png, write member name, 3 color then display
|
||||
qrencode -s 3 -o "./tmp/rotate.png" ${PUBKEY}
|
||||
composite -compose Over -gravity East "./tmp/rotate.png" "./G1(gris).png" "./tmp/image.png"
|
||||
|
||||
convert -font 'Times-Bold' -pointsize 20 -fill black -draw 'text 10,20 "'"${MEMBER}"'"' "./tmp/image.png" "./tmp/uid.png"
|
||||
|
||||
fi
|
||||
|
||||
convert "./tmp/uid.png" -strip +dither -colors 3 -treedepth 3 -remap inkymap.png "./result.png"
|
||||
# Backup inky display
|
||||
cp "./result.png" "./SCAN/${PUBKEY}/inky.png"
|
||||
cp "./tmp/uid.png" "./IPFS/MEMBERS/${MEMBER}/g1_avatar.png"
|
||||
python inky_display.py
|
||||
|
||||
done
|
Loading…
Reference in New Issue