diff --git a/MosReport.py b/MosReport.py new file mode 100644 index 0000000..044eb86 --- /dev/null +++ b/MosReport.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- + +def get_report(items): + """Returns plaintext and csv data for given items. + *items* is the result of MosDb.get_daily_oa() + """ + longest_name = 9 + longest_author = 5 + for i in items: + if len(i["name"]) > longest_name: + longest_name = len(i["name"]) + if len(i["createdBy"]) > longest_author: + longest_author = len(i["createdBy"]) + + # Output table + output_text = ("{:19} | {:" + str(longest_name) + "} | {:" + str(longest_author) + "} | {:>5} | {:>5} | {:>5}\n").format( + "Datum", + "OnAir-MAZ", + "Autor", + "LUFS", + "LRA", + "LDIFF" + ) + output_text += ("{:-<19} | {:-<" + str(longest_name) + "} | {:-<" + str(longest_author) + "} | {:->5} | {:->5} | {:->5}\n").format("", "", "", "", "", "") + # Output CSV, use BOM because Excel is ignorant + output_csv = "\ufeff" + output_csv += "objId,planningId,created,name,createdBy,lufs,lra,ludiff\n" + for i in items: + lu = i["lu"] + if lu is None: + lu = "n/a" + lra = "-" + ldiff = "-" + elif lu == -99.0: + lu = "-∞" + lra = "-" + ldiff = "-" + else: + lu = "{:>5.1f}".format(lu) + lra = "{:>5.1f}".format(i["lra"]) + ldiff = "{:>5.1f}".format(i["ldiff"]) + + output_text += ("{} | {:" + str(longest_name) + "} | {:" + str(longest_author) + "} | {:>5} | {:>5} | {:>5}\n").format( + i["created"], + i["name"], + i["createdBy"], + lu, + lra, + ldiff + ) + output_csv += ("{},{},{},\"{}\",\"{}\",{},{},{}").format( + i["objId"], + i["planningId"], + i["created"], + i["name"], + i["createdBy"], + i["lu"], + i["lra"], + i["ldiff"] + ) + "\n" + return (output_text, output_csv) + diff --git a/show_today.py b/show_today.py index fdbab43..39a086f 100755 --- a/show_today.py +++ b/show_today.py @@ -4,6 +4,7 @@ import os import sys import MosDb +import MosReport db = MosDb.MosDb() @@ -11,60 +12,7 @@ items = db.get_daily_oa() #items = db.get_daily_oa("-1 day") db.finish() -longest_name = 9 -longest_author = 5 -for i in items: - if len(i["name"]) > longest_name: - longest_name = len(i["name"]) - if len(i["createdBy"]) > longest_author: - longest_author = len(i["createdBy"]) +(output_text, output_csv) = MosReport.get_report(items) -# Output table -output_text = ("{:19} | {:" + str(longest_name) + "} | {:" + str(longest_author) + "} | {:>5} | {:>5} | {:>5}\n").format( - "Datum", - "OnAir-MAZ", - "Autor", - "LUFS", - "LRA", - "LDIFF" -) -output_text += ("{:-<19} | {:-<" + str(longest_name) + "} | {:-<" + str(longest_author) + "} | {:->5} | {:->5} | {:->5}\n").format("", "", "", "", "", "") -# Output CSV, use BOM because Excel is ignorant -output_csv = "\ufeff" -output_csv += "objId,planningId,created,name,createdBy,lufs,lra,ludiff\n" -for i in items: - lu = i["lu"] - if lu is None: - lu = "n/a" - lra = "-" - ldiff = "-" - elif lu == -99.0: - lu = "-∞" - lra = "-" - ldiff = "-" - else: - lu = "{:>5.1f}".format(lu) - lra = "{:>5.1f}".format(i["lra"]) - ldiff = "{:>5.1f}".format(i["ldiff"]) - - output_text += ("{} | {:" + str(longest_name) + "} | {:" + str(longest_author) + "} | {:>5} | {:>5} | {:>5}\n").format( - i["created"], - i["name"], - i["createdBy"], - lu, - lra, - ldiff - ) - output_csv += ("{},{},{},\"{}\",\"{}\",{},{},{}").format( - i["objId"], - i["planningId"], - i["created"], - i["name"], - i["createdBy"], - i["lu"], - i["lra"], - i["ldiff"] - ) + "\n" - print(output_text) print(output_csv) diff --git a/show_yesterday.py b/show_yesterday.py new file mode 100755 index 0000000..d142364 --- /dev/null +++ b/show_yesterday.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +import sys +import MosDb +import MosReport + +db = MosDb.MosDb() + +#items = db.get_daily_oa() +items = db.get_daily_oa("-1 day") +db.finish() + +(output_text, output_csv) = MosReport.get_report(items) + +print(output_text) +print(output_csv)