From e451a10bf3c9514432ceef0f23a2b1abf674fc19 Mon Sep 17 00:00:00 2001 From: Phil Morrell Date: Sun, 17 Apr 2022 14:14:22 +0100 Subject: [PATCH] refactor python to support multiple actions * executable, license header * prefer `with open` style to auto-close file handles * keep hardcoding within __main__ --- script.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) mode change 100644 => 100755 script.py diff --git a/script.py b/script.py old mode 100644 new mode 100755 index f1be722..657a30a --- a/script.py +++ b/script.py @@ -1,10 +1,15 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: CC0-1.0 + from mako.template import Template import json -import itertools -import argparse -appTemplate = Template(filename='./spaces.html') -f = open('libregamingspaces.json') -spaces=json.load(f) +def render(spaces, template): + appTemplate = Template(filename=template) + print(appTemplate.render(s=spaces)) -print(appTemplate.render(s=spaces)) +if __name__ == '__main__': + with open('libregamingspaces.json') as f: + spaces = json.load(f) + + render(spaces, './spaces.html')