Compare commits

...

6 Commits

Author SHA1 Message Date
Tanner 348c010b7c Ignore aider 2026-06-13 16:34:36 -06:00
tanner 8b65026401 Add drugwars game 2026-02-18 03:54:21 +00:00
tanner 52c417b176 Add Protovac quotes 2025-11-19 02:26:05 +00:00
tanner 6ff226543d Unhide forum label menu option 2025-08-03 16:42:36 -06:00
tanner fe299ba2b5 Finish forum label generation 2025-08-03 16:42:00 -06:00
tanner 7bc5e02a7c Hide forum thread label option for now 2025-08-03 16:11:25 -06:00
3 changed files with 164 additions and 16 deletions
+1
View File
@@ -115,3 +115,4 @@ venv.bak/
secrets.py
tmp.png
.aider*
+60 -7
View File
@@ -16,7 +16,7 @@ def print_forum_label(thread):
url = 'https://forum.protospace.ca/t/{}/'.format(thread['id'])
qr = qrcode.make(url, version=6, box_size=9)
im.paste(qr, (840, 325))
im.paste(qr, (840, 150))
item_size = 150
@@ -24,14 +24,67 @@ def print_forum_label(thread):
while w > 1200:
item_size -= 5
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', item_size)
w, h = draw.textsize(thread['title'], font=font)
w, h = draw.textsize(url, font=font)
x, y = (width - w) / 2, ((height - h) / 2) - 140
draw.text((x, y), thread['title'], font=font, fill='black')
x, y = (width - w) / 2, ((height - h) / 2) + 300
draw.text((x, y), url, font=font, fill='black')
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 100)
draw.text((100, 410), 'Out of stock?', font=font, fill='black')
draw.text((150, 560), 'Scan here:', font=font, fill='black')
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf', 80)
draw.text((120, 150), 'Forum Thread', font=font, fill='black')
text = thread['title']
MARGIN = 50
MAX_W, MAX_H, PAD = 900 - (MARGIN*2), 450 - (MARGIN*2), 5
def fit_text(text, font_size):
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', font_size)
for cols in range(100, 1, -4):
print('trying size', font_size, 'cols', cols)
paragraph = textwrap.wrap(text, width=cols, break_long_words=False)
total_h = -PAD
total_w = 0
for line in paragraph:
w, h = draw.textsize(line, font=font)
if w > total_w:
total_w = w
total_h += h + PAD
if total_w <= MAX_W and total_h < MAX_H:
return True, paragraph, total_h
return False, [], 0
font_size_range = [1, 500]
# Thanks to Alex (UDIA) for the binary search algorithm
while abs(font_size_range[0] - font_size_range[1]) > 1:
font_size = sum(font_size_range) // 2
image_fit, check_para, check_h = fit_text(text, font_size)
if image_fit:
print('Does fit')
font_size_range = [font_size, font_size_range[1]]
good_size = font_size
paragraph = check_para
total_h = check_h
else:
print('Does not fit')
font_size_range = [font_size_range[0], font_size]
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', good_size)
offset = height - MAX_H - MARGIN
start_h = -100 + offset
current_h = start_h
for line in paragraph:
w, h = draw.textsize(line, font=font)
x, y = (MAX_W - w) / 2, current_h
draw.text((x+MARGIN, y), line, font=font, fill='black')
current_h += h + PAD
im.save('tmp.png')
+103 -9
View File
@@ -49,6 +49,7 @@ KEY_SPACE = 32
TIMEZONE_CALGARY = pytz.timezone('America/Edmonton')
DRUGWARS_LOCATION = '/home/pi/protovac/env/bin/drugwars'
NETHACK_LOCATION = '/usr/games/nethack'
MORIA_LOCATION = '/usr/games/moria'
_2048_LOCATION = '/home/pi/2048-cli/2048'
@@ -56,6 +57,7 @@ FROTZ_LOCATION = '/usr/games/frotz'
HITCHHIKERS_LOCATION = '/home/pi/frotz/hhgg.z3'
SUDOKU_LOCATION = '/usr/games/nudoku'
HAS_DRUGWARS = os.path.isfile(DRUGWARS_LOCATION)
HAS_NETHACK = os.path.isfile(NETHACK_LOCATION)
HAS_MORIA = os.path.isfile(MORIA_LOCATION)
HAS_2048 = os.path.isfile(_2048_LOCATION)
@@ -256,6 +258,39 @@ QUOTES = [
'ACID BURN',
'CEREAL KILLER',
'ZERO COOL',
'ASK ME HOW I SAVED 15% ON MY CAR INSURANCE',
'TELL YOUR CAT I SAID PSP PSP PSP',
'I\'M BEGGING YOU, DON\'T SAY HI',
'BACK 2 BACK HOTDOG EATING WORLD CHAMPION',
'I ATE A BROWNIE ONCE',
'THIS ISN\'T ACTUALLY MY NAME',
'I OFTEN WONDER HOW I EVEN GOT HERE',
'YOU READ THIS, NOW WE MUST DUEL',
'DAVE\'S ARCH NEMESIS',
'EXCEPTIONALLY MID',
'VOTE ME 4 PREZADENT',
'PREVALENT IN OTHER WAYS',
'SCINTILLATING CHATOYANCY',
'TRAIN EXPERT',
'ASSISTANT MANAGER',
'WOW, ANOTHER TAG LINE',
'I SURVIVED VETTING AND ALL I GOT WAS THIS LOUSY NAME-TAG',
'NOT GUEST',
'WHEN WAS THE LAST TIME YOU TOOK OUT A GARBAGE?',
'YOU HAD ME AT BATMAN',
'DAD?',
'LEAD PROJECT UN-FINISHER',
'NOODLE CONNOISSEUR',
'GARTH\'S #1 FAN',
'UNVETTABLE',
'B-',
'CLOWN CAR DRIVER',
'IS A NAME TAG ON BREAD CONSIDERED A SANDWICH?',
'IS A NAME TAG FOLDED IN HALF CONSIDERED A TACO?',
'DISHWASHER SAFE',
'WET NOODLE',
'I\'M HERE FOR THE SIMULATION',
'BIRDS ARE NOT REAL',
]
random.shuffle(QUOTES)
@@ -470,12 +505,12 @@ def print_forum_label(thread):
width, height = im.size
draw = ImageDraw.Draw(im)
logging.info('Printing forum thread: %s', thread['title'])
logging.info('Printing forum thread ID: %s, title: %s', thread['id'], thread['title'])
url = 'https://forum.protospace.ca/t/{}/'.format(thread['id'])
qr = qrcode.make(url, version=6, box_size=9)
im.paste(qr, (840, 325))
im.paste(qr, (840, 150))
item_size = 150
@@ -483,14 +518,63 @@ def print_forum_label(thread):
while w > 1200:
item_size -= 5
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', item_size)
w, h = draw.textsize(item, font=font)
w, h = draw.textsize(url, font=font)
x, y = (width - w) / 2, ((height - h) / 2) - 140
draw.text((x, y), item, font=font, fill='black')
x, y = (width - w) / 2, ((height - h) / 2) + 300
draw.text((x, y), url, font=font, fill='black')
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 100)
draw.text((100, 410), 'Out of stock?', font=font, fill='black')
draw.text((150, 560), 'Scan here:', font=font, fill='black')
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf', 80)
draw.text((120, 150), 'Forum Thread', font=font, fill='black')
text = thread['title']
MARGIN = 50
MAX_W, MAX_H, PAD = 900 - (MARGIN*2), 450 - (MARGIN*2), 5
def fit_text(text, font_size):
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', font_size)
for cols in range(100, 1, -4):
paragraph = textwrap.wrap(text, width=cols, break_long_words=False)
total_h = -PAD
total_w = 0
for line in paragraph:
w, h = draw.textsize(line, font=font)
if w > total_w:
total_w = w
total_h += h + PAD
if total_w <= MAX_W and total_h < MAX_H:
return True, paragraph, total_h
return False, [], 0
font_size_range = [1, 500]
# Thanks to Alex (UDIA) for the binary search algorithm
while abs(font_size_range[0] - font_size_range[1]) > 1:
font_size = sum(font_size_range) // 2
image_fit, check_para, check_h = fit_text(text, font_size)
if image_fit:
font_size_range = [font_size, font_size_range[1]]
good_size = font_size
paragraph = check_para
total_h = check_h
else:
font_size_range = [font_size_range[0], font_size]
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', good_size)
offset = height - MAX_H - MARGIN
start_h = -100 + offset
current_h = start_h
for line in paragraph:
w, h = draw.textsize(line, font=font)
x, y = (MAX_W - w) / 2, current_h
draw.text((x+MARGIN, y), line, font=font, fill='black')
current_h += h + PAD
im.save('tmp.png')
os.system('lp -d dymo tmp.png > /dev/null 2>&1')
@@ -1086,6 +1170,8 @@ while True:
stdscr.addstr(14, 4, '[H] Hitchhiker\'s Guide to the Galaxy', curses.A_REVERSE if highlight_keys else 0)
if HAS_SUDOKU:
stdscr.addstr(16, 4, '[S] Sudoku', curses.A_REVERSE if highlight_keys else 0)
if HAS_DRUGWARS:
stdscr.addstr(18, 4, '[D] Drugwars', curses.A_REVERSE if highlight_keys else 0)
stdscr.addstr(23, 1, '[B] Back', curses.A_REVERSE if highlight_keys else 0)
@@ -1608,7 +1694,7 @@ I will be terse in my responses.
stdscr.keypad(False)
curses.echo()
curses.endwin()
logging.info('Spawning moria.')
logging.info('Spawning 2048.')
os.system(_2048_LOCATION)
break
elif button == 'm' and HAS_MORIA:
@@ -1627,6 +1713,14 @@ I will be terse in my responses.
logging.info('Spawning nethack.')
os.system(NETHACK_LOCATION)
break
elif button == 'd' and HAS_DRUGWARS:
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()
logging.info('Spawning drugwars.')
os.system(DRUGWARS_LOCATION)
break
else:
try_highlight()