-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
69 lines (51 loc) · 2.21 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
The main script is an example which shows how to integrate the helper functions into your own code.
If you want to run the example, add a "secrets.json" file to the root directory of this project.
The file should contain the following information:
{
"username": "ADD_YOUR_OWN_USERNAME_HERE",
"password": "ADD_YOUR_OWN_PASSWORD_HERE"
}
"""
# Import helper function for Cognitive OpenAPI requests
import endpoints_managment_ui as via_mgmt_ui
import endpoints_api_key as via_api_key
# Import other modules
from tqdm import tqdm # progress bar
import logging
# Configure the logging module
logging.basicConfig(
level=logging.INFO, # Set the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
format='%(asctime)s - %(levelname)s - %(message)s', # Define the log message format
# filename='example.log', # Specify the log file
# filemode='a' # Use 'a' to append to the log file, 'w' to overwrite it
)
################################################################################################
# Functions
"""
Add your own function which make use of the helper functions
"""
################################################################################################
# Execution
def main(base_url, username, password):
# e.g use the management ui to query all admin users
logging.info("Getting all Admin users")
admin_user_id_list = via_mgmt_ui.get_admin_user_ids(base_url, username, password)
"""
Add your own code here
"""
################################################################################################
# Run the script with configs
if __name__ == "__main__":
# Configs
API_URL = "ADD_YOUR_OWN_COGNIGY_API_URL_HERE"
#### For Management UI Authentication
# If you want to use the management UI to get the credentials, you can use the following code
logging.info(f"Using {API_URL} as base URL")
USERNAME, PASSWORD = via_mgmt_ui.load_management_ui_credentials("secrets.json")
#### For API Key Authentication ####
"""
Add your own code here. Change the main function so it passes your API key to the helper functions
"""
# Main functionality
main(API_URL, USERNAME, PASSWORD)