Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parses a monthly PSTN usage report from Office 365 to report on the minutes consumed per destination phone number for dial-out.
import csv
usage_tracker = {}
report_file = "./pstn_report.csv"
with open(report_file, "r", newline="") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row["Call Type"] == "conf_out":
seconds = int(row["Duration Seconds"])
if row["Destination Number"] in usage_tracker.keys():
usage_tracker[row["Destination Number"]] += seconds
else:
usage_tracker[row["Destination Number"]] = seconds
usage_tuple_list = sorted(usage_tracker.items(), key=lambda x: x[1], reverse=True)
total_minutes = 0
for element in usage_tuple_list:
current_minutes = round(element[1] / 60)
total_minutes += current_minutes
print(element[0] + ": " + str(current_minutes))
print("============================")
print(total_minutes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.