Fix location of template.html and add --refresh

This commit is contained in:
Edward Betts 2023-12-22 15:38:29 +00:00
parent a7fcae14b1
commit 4bae8bc64a

View file

@ -50,10 +50,10 @@ def download_bugs(state: str) -> list[Bug]:
return all_bugs
def get_all_bugs() -> list[Bug]:
def get_all_bugs(refresh: bool = False) -> list[Bug]:
"""Get all bugs."""
filename = config.get("output", "cache")
if os.path.exists(filename):
if not refresh and os.path.exists(filename):
with open(filename) as fh:
return typing.cast(list[Bug], json.load(fh))
@ -104,12 +104,16 @@ def count_open_bugs(bug_reports: list[Bug]) -> list[tuple[str, int]]:
def main() -> None:
"""Grab bug reports and generate chart."""
bug_reports = get_all_bugs()
refresh = len(sys.argv) > 1 and sys.argv[1] == "--refresh"
bug_reports = get_all_bugs(refresh)
open_bugs_over_time = count_open_bugs(bug_reports)
json_data = json.dumps(open_bugs_over_time)
template_html = open("template.html").read()
script_dir = os.path.dirname(os.path.abspath(__file__))
template_path = os.path.join(script_dir, "template.html")
with open(template_path, "r") as fh:
template_html = fh.read()
dest = config.get("output", "dest")
with open(dest, "w") as out:
out.write(template_html.replace("jsonData = []", "jsonData = " + json_data))