Add expires date to sheet label

This commit is contained in:
Tanner Collin 2022-10-18 23:27:11 -06:00
parent 26da145090
commit 85db447af7
2 changed files with 18 additions and 4 deletions

11
main.py
View File

@ -25,7 +25,7 @@ import json
import textwrap
import random
from PIL import Image, ImageEnhance, ImageFont, ImageDraw
from datetime import datetime, timezone
from datetime import datetime, timezone, timedelta
try:
import secrets
@ -254,6 +254,11 @@ def print_sheet_label(name, contact):
d = d.astimezone(TIMEZONE_CALGARY)
return d.strftime('%b %-d, %Y')
def get_expiry_date():
d = datetime.now(tz=timezone.utc) + timedelta(days=90)
d = d.astimezone(TIMEZONE_CALGARY)
return d.strftime('%b %-d, %Y')
name_size = 85
contact_size = 65
date_size = 65
@ -270,7 +275,9 @@ def print_sheet_label(name, contact):
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', date_size)
date_line = 'Printed: ' + get_date()
draw.text((20, 625), date_line, font=font, fill='black')
draw.text((20, 590), date_line, font=font, fill='black')
date_line = 'EXPIRES: ' + get_expiry_date()
draw.text((20, 680), date_line, font=font, fill='black')
im.save('tmp.png')
os.system('lp -d dymo tmp.png > /dev/null 2>&1')

View File

@ -1,7 +1,7 @@
from PIL import Image, ImageEnhance, ImageFont, ImageDraw
import requests
import pytz
from datetime import datetime, timezone
from datetime import datetime, timezone, timedelta
TIMEZONE_CALGARY = pytz.timezone('America/Edmonton')
@ -12,6 +12,11 @@ def print_sheet_label(name, contact):
d = d.astimezone(TIMEZONE_CALGARY)
return d.strftime('%b %-d, %Y')
def get_expiry_date():
d = datetime.now(tz=timezone.utc) + timedelta(days=90)
d = d.astimezone(TIMEZONE_CALGARY)
return d.strftime('%b %-d, %Y')
name_size = 85
contact_size = 65
date_size = 65
@ -28,7 +33,9 @@ def print_sheet_label(name, contact):
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', date_size)
date_line = 'Printed: ' + get_date()
draw.text((20, 625), date_line, font=font, fill='black')
draw.text((20, 590), date_line, font=font, fill='black')
date_line = 'EXPIRES: ' + get_expiry_date()
draw.text((20, 680), date_line, font=font, fill='black')
im.save('tmp.png')