· last year · Feb 18, 2025, 07:00 PM
1import csv
2import json
3import re
4import requests
5from urllib3 import disable_warnings
6from urllib3.exceptions import InsecureRequestWarning
7import xmltodict
8
9"""Warning: this script has not been tested in production.
10It has no throttling or error checking. Don't complain to me
11if you tank your production server.
12
13This will download all user voicename files to the current
14directory with the name "alias.wav"
15
16Update the uxcnhost, cupiuser, and cupipass to match your environment.
17"""
18disable_warnings(InsecureRequestWarning)
19
20ucxnhost = ""
21cupiuser = ''
22cupipass = ''
23
24def vmrest_get(ucxnhost: str, uri: str, username:str, password:str, filename: str = None):
25
26 url = f"https://{ucxnhost}/{uri}"
27 basic_auth = requests.auth.HTTPBasicAuth(username, password)
28 response = requests.get(url, auth=basic_auth, verify=False)
29
30 if response.status_code == 404:
31 return None
32 elif response.status_code == 200:
33 if filename:
34 with open(filename, 'wb') as f_output:
35 f_output.write(response.content)
36 return True
37 else:
38 response_dict = xmltodict.parse(response.content)
39 return response_dict
40
41# Can use a query to limit the users returned if needed
42allusers = vmrest_get(ucxnhost, "/vmrest/users?query=(alias startswith a)", cupiuser, cupipass)
43#allusers = vmrest_get(ucxnhost, "/vmrest/users", cupiuser, cupipass)
44for user in allusers['Users']['User']:
45 user_uri = user['URI']
46 user_info = vmrest_get(ucxnhost, user_uri, cupiuser, cupipass)
47 #print (user_info)
48 user_alias = user_info['User']['Alias']
49 if "VoiceNameURI" in user_info['User']:
50 user_voicename_uri = user_info['User']['VoiceNameURI']
51 print (f"Alias: {user_alias}\tVoiceNameURI: {user_voicename_uri}")
52 user_voicename_file = f"{user_alias}.wav"
53 download = vmrest_get(ucxnhost, user_voicename_uri, cupiuser, cupipass, filename=user_voicename_file)
54 else:
55 print (f"Alias: {user_alias}\tVoiceNameURI: NULL")
56