-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_name_tag.py
executable file
·68 lines (56 loc) · 2.64 KB
/
print_name_tag.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
import argparse
from src.backend import makeradmin
from src.test import makeradmin_mock
from src.backend.member import Member
from src.backend.member import NoMatchingMemberNumber
from src.label import creator as label_creator
from src.label import printer as label_printer
from time import time
from src.util.logger import init_logger, get_logger
import config
import sys
init_logger("print_label")
logger = get_logger()
start_command = " ".join(sys.argv)
def print_label(label, no_printer: bool = False):
if no_printer:
file_name = f'Name_tag_{str(int(time()))}.png'
logger.info(
f'Program run with --no-printer, storing label image to {file_name} instead of printing it.')
print(f"Saving name tag {file_name}")
label.save(file_name)
label.show()
else:
label_printer.print_label(label.label)
def main():
logger.info(f"Starting {sys.argv[0]} as \n\t{start_command}")
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--token_path", help="Path to Makeradmin token.", default=config.makeradmin_token_filename)
parser.add_argument("--no-backend", action="store_true", help="Mock backend (fake requests)")
parser.add_argument("-u", "--maker-admin-base-url",
default=config.maker_admin_base_url,
help="Base url of maker admin backend")
parser.add_argument("--no-printer", action="store_true", help="Mock label printer (save label to file instead)")
parser.add_argument("member_number", type=int, help="The member number of the member you want to print the tag for")
args = parser.parse_args()
config.no_backend = args.no_backend
config.no_printer = args.no_printer
config.token_path = args.token_path
config.maker_admin_base_url = args.maker_admin_base_url
if args.no_backend:
makeradmin_client = makeradmin_mock.MakerAdminClient()
else:
makeradmin_client = makeradmin.MakerAdminClient(base_url=config.maker_admin_base_url,
token_path=config.token_path)
while not makeradmin_client.is_logged_in():
logger.warning("The makeradmin client is not logged in")
makeradmin_client.login()
try:
member = Member.from_member_number(makeradmin_client, args.member_number)
label = label_creator.create_name_tag(member.member_number, member.get_name(), member.membership.end_date)
print_label(label, config.no_printer)
except NoMatchingMemberNumber:
logger.error(f"Member number {args.member_number} did not match any known member")
if __name__ == "__main__":
main()