From 85db447af779ee229ee15df2f533aab267c0438b Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Tue, 18 Oct 2022 23:27:11 -0600 Subject: [PATCH] Add expires date to sheet label --- main.py | 11 +++++++++-- sheet_label.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 8a825a0..2b49f15 100755 --- a/main.py +++ b/main.py @@ -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') diff --git a/sheet_label.py b/sheet_label.py index fb19fe3..3a74b96 100644 --- a/sheet_label.py +++ b/sheet_label.py @@ -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')