From 8b2ce44bbe1456088f72d677a48cb230cf0991e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Solbj=C3=B8rg?= Date: Mon, 1 Apr 2019 22:30:12 +0200 Subject: =?UTF-8?q?chore:=20Move=20switch=20label=20generation=20to=20own?= =?UTF-8?q?=20file=20=F0=9F=A7=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- switches.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 switches.py (limited to 'switches.py') diff --git a/switches.py b/switches.py new file mode 100644 index 0000000..dbc7ece --- /dev/null +++ b/switches.py @@ -0,0 +1,45 @@ +from gondul import fetch_gondul_switches + +switch_label_format = "%(switch_name)s-%(switch_num)s" +switch_label_layout = """ + + + +%s +""" +switch_label_page = '
%s
' + + +def generate_label(switch_name, switch_number): + return switch_label_page % switch_label_format % { + "switch_name": switch_name, + "switch_num": switch_number, + } + + +def generate_labels(switches): + labels = list(map(lambda switch: generate_label( + switch[1:].split("-")[0], switch.split("-")[1]), switches)) + + return switch_label_layout % "".join(labels) + + +def write_html_to_file(html, outfile="switch_labels.html"): + with open(outfile, "w") as f: + f.write(html) + print("Wrote labels to '{}'.\nOpen the file in your browser and print it.".format(outfile)) + + +def make_switch_labels(): + switches = fetch_gondul_switches() + labels = generate_labels(switches) + write_html_to_file(labels) -- cgit v1.2.3