Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from urllib3 import disable_warnings
- from urllib3.exceptions import InsecureRequestWarning
- import xmltodict
- """Warning: this script has not been tested in production.
- It has no throttling or error checking. Don't complain to me
- if you tank your production server.
- This will download all user voicename files to the current
- directory with the name "alias.wav"
- Update the uxcnhost, cupiuser, and cupipass to match your environment.
- """
- disable_warnings(InsecureRequestWarning)
- ucxnhost = ""
- cupiuser = ''
- cupipass = ''
- def vmrest_get(ucxnhost: str, uri: str, username:str, password:str, filename: str = None):
- url = f"https://{ucxnhost}/{uri}"
- basic_auth = requests.auth.HTTPBasicAuth(username, password)
- response = requests.get(url, auth=basic_auth, verify=False)
- if response.status_code == 404:
- return None
- elif response.status_code == 200:
- if filename:
- with open(filename, 'wb') as f_output:
- f_output.write(response.content)
- return True
- else:
- response_dict = xmltodict.parse(response.content)
- return response_dict
- # Can use a query to limit the users returned if needed
- allusers = vmrest_get(ucxnhost, "/vmrest/users?query=(alias startswith a)", cupiuser, cupipass)
- #allusers = vmrest_get(ucxnhost, "/vmrest/users", cupiuser, cupipass)
- for user in allusers['Users']['User']:
- user_uri = user['URI']
- user_info = vmrest_get(ucxnhost, user_uri, cupiuser, cupipass)
- #print (user_info)
- user_alias = user_info['User']['Alias']
- if "VoiceNameURI" in user_info['User']:
- user_voicename_uri = user_info['User']['VoiceNameURI']
- print (f"Alias: {user_alias}\tVoiceNameURI: {user_voicename_uri}")
- user_voicename_file = f"{user_alias}.wav"
- download = vmrest_get(ucxnhost, user_voicename_uri, cupiuser, cupipass, filename=user_voicename_file)
- else:
- print (f"Alias: {user_alias}\tVoiceNameURI: NULL")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement