Add 'switchvox-did-usage-report'
This commit is contained in:
40
switchvox-did-usage-report
Normal file
40
switchvox-did-usage-report
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import json, csv, os, sys, argparse
|
||||||
|
from requests import Session
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
SWVX_API_USERNAME = os.getenv('SWVX_API_USERNAME')
|
||||||
|
SWVX_API_PASSWORD = os.getenv('SWVX_API_PASSWORD')
|
||||||
|
regcode = os.getenv('regcode')
|
||||||
|
|
||||||
|
def load_csv(filename):
|
||||||
|
"""Reads a csv file and returns as list of dict records"""
|
||||||
|
with open(filename, 'r') as f:
|
||||||
|
dict_reader = csv.DictReader(f)
|
||||||
|
list_of_dict = list(dict_reader)
|
||||||
|
return list_of_dict
|
||||||
|
|
||||||
|
def load_file_list(filename):
|
||||||
|
"""Reads file with single column list of records"""
|
||||||
|
list_of_items = []
|
||||||
|
with open(filename, 'r') as f:
|
||||||
|
list_of_items.append(f.readline())
|
||||||
|
return list_of_items
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_report(dids, regcode, **params):
|
||||||
|
session = Session()
|
||||||
|
session.auth = (SWVX_API_USERNAME,SWVX_API_PASSWORD)
|
||||||
|
|
||||||
|
params['paginate'] = True
|
||||||
|
r = session.get(f"https://api.switchvoxuc.com/switchvox/{regcode}/reports/calls/dids", params=**params)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
logger.info(f"Starting report")
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--dids', type=str, required=True)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user