-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsample.py
More file actions
132 lines (106 loc) · 4.82 KB
/
Copy pathsample.py
File metadata and controls
132 lines (106 loc) · 4.82 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!python3
import sys
import argparse
import requests
import urllib3
from panopto_sessions import PanoptoSessions
from os.path import dirname, join, abspath
sys.path.insert(0, abspath(join(dirname(__file__), '..', 'common')))
from panopto_oauth2 import PanoptoOAuth2
def parse_argument():
parser = argparse.ArgumentParser(description='Sample of Folders API')
parser.add_argument('--server', dest='server', required=True, help='Server name as FQDN')
parser.add_argument('--client-id', dest='client_id', required=True, help='Client ID of OAuth2 client')
parser.add_argument('--client-secret', dest='client_secret', required=True, help='Client Secret of OAuth2 client')
parser.add_argument('--session-id', dest='session_id', required=False, help='The ID of the session to start with.')
parser.add_argument('--skip-verify', dest='skip_verify', action='store_true', required=False, help='Skip SSL certificate verification. (Never apply to the production code)')
return parser.parse_args()
def main():
args = parse_argument()
if args.skip_verify:
# This line is needed to suppress annoying warning message.
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# Use requests module's Session object in this example.
# ref. https://2.python-requests.org/en/master/user/advanced/#session-objects
requests_session = requests.Session()
requests_session.verify = not args.skip_verify
# Load OAuth2 logic
oauth2 = PanoptoOAuth2(args.server, args.client_id, args.client_secret, not args.skip_verify)
# Load Sessions API logic
sessions = PanoptoSessions(args.server, not args.skip_verify, oauth2)
if args.session_id is not None:
current_session_id = args.session_id
else:
current_session_id = None
# Load the initial session (if any) and display the options menu
while True:
print('----------------------------')
if current_session_id is not None:
session = get_and_display_session(sessions, current_session_id)
current_session_id = process_selection(sessions, current_session_id)
def get_and_display_session(sessions, session_id):
'''
Returning session object that is returned by API.
None if it is top level folder.
'''
print()
print('Session:')
session = sessions.get_session(session_id)
print(' Name: {0}'. format(session['Name']))
print(' Id: {0}'. format(session['Id']))
print(' Folder Id: {0}'. format(session['Folder']))
print(' ViewerUrl: {0}'. format(session['Urls']['ViewerUrl']))
print(' EmbedUrl: {0}'. format(session['Urls']['EmbedUrl']))
print(' ShareSettingsUrl: {0}'. format(session['Urls']['ShareSettingsUrl']))
print(' DownloadUrl: {0}'. format(session['Urls']['DownloadUrl']))
print(' CaptionDownloadUrl: {0}'. format(session['Urls']['CaptionDownloadUrl']))
print(' EditorUrl: {0}'. format(session['Urls']['EditorUrl']))
print(' CreatedBy: {0}'. format(session['CreatedBy']['Username']))
print(' StartTime: {0}'. format(session['StartTime']))
print(' Description: {0}'. format(session['Description']))
return session
def process_selection(sessions, current_session_id):
new_session_id = current_session_id
print()
if current_session_id is not None:
print('[R] Rename this session')
print('[D] Delete this session')
print('[S] Search sessions')
print()
selection = input('Enter a command: ')
if selection.lower() == 'r' and current_session_id is not None:
rename_session(sessions, current_session_id)
elif selection.lower() == 'd' and current_session_id is not None:
if delete_session(sessions, current_session_id):
new_session_id = None
elif selection.lower() == 's':
result = search_sessions(sessions)
if result is not None:
new_session_id = result
else:
print('Invalid command.')
return new_session_id
def rename_session(sessions, session_id):
new_name = input('Enter new name: ')
return sessions.update_session_name(session_id, new_name)
def delete_session(sessions, session_id):
return sessions.delete_session(session_id)
def search_sessions(sessions):
query = input('Enter search keyword: ')
entries = sessions.search_sessions(query)
if len(entries) == 0:
print(' No results.')
return None
for index in range(len(entries)):
print(' [{0}]: {1}'.format(index, entries[index]['Name']))
selection = input('Enter the number (or just enter to stay on the current session): ')
new_session_id = None
try:
index = int(selection)
if 0 <= index < len(entries):
new_session_id = entries[index]['Id']
except:
pass
return new_session_id
if __name__ == '__main__':
main()