Created
April 28, 2020 22:34
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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