Skip to content

Instantly share code, notes, and snippets.

@JFFail
Created April 28, 2020 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JFFail/a2da00a7c379d2805825a27a07bc89b4 to your computer and use it in GitHub Desktop.
Save JFFail/a2da00a7c379d2805825a27a07bc89b4 to your computer and use it in GitHub Desktop.
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