Add expires date to sheet label
This commit is contained in:
parent
26da145090
commit
85db447af7
11
main.py
11
main.py
|
@ -25,7 +25,7 @@ import json
|
||||||
import textwrap
|
import textwrap
|
||||||
import random
|
import random
|
||||||
from PIL import Image, ImageEnhance, ImageFont, ImageDraw
|
from PIL import Image, ImageEnhance, ImageFont, ImageDraw
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone, timedelta
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import secrets
|
import secrets
|
||||||
|
@ -254,6 +254,11 @@ def print_sheet_label(name, contact):
|
||||||
d = d.astimezone(TIMEZONE_CALGARY)
|
d = d.astimezone(TIMEZONE_CALGARY)
|
||||||
return d.strftime('%b %-d, %Y')
|
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
|
name_size = 85
|
||||||
contact_size = 65
|
contact_size = 65
|
||||||
date_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)
|
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', date_size)
|
||||||
date_line = 'Printed: ' + get_date()
|
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')
|
im.save('tmp.png')
|
||||||
os.system('lp -d dymo tmp.png > /dev/null 2>&1')
|
os.system('lp -d dymo tmp.png > /dev/null 2>&1')
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from PIL import Image, ImageEnhance, ImageFont, ImageDraw
|
from PIL import Image, ImageEnhance, ImageFont, ImageDraw
|
||||||
import requests
|
import requests
|
||||||
import pytz
|
import pytz
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone, timedelta
|
||||||
|
|
||||||
TIMEZONE_CALGARY = pytz.timezone('America/Edmonton')
|
TIMEZONE_CALGARY = pytz.timezone('America/Edmonton')
|
||||||
|
|
||||||
|
@ -12,6 +12,11 @@ def print_sheet_label(name, contact):
|
||||||
d = d.astimezone(TIMEZONE_CALGARY)
|
d = d.astimezone(TIMEZONE_CALGARY)
|
||||||
return d.strftime('%b %-d, %Y')
|
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
|
name_size = 85
|
||||||
contact_size = 65
|
contact_size = 65
|
||||||
date_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)
|
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', date_size)
|
||||||
date_line = 'Printed: ' + get_date()
|
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')
|
im.save('tmp.png')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user