-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathR1_hospitality_edition.py
68 lines (56 loc) · 2.25 KB
/
R1_hospitality_edition.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
import warnings
import csv
from datetime import datetime
warnings.filterwarnings("ignore", message="Unverified HTTPS request")
# Import classes
from R1_API import R1_API_calls
# Constants
R1HOST = 'api.ruckus.cloud'
TENANT_ID = 'your_tenant_id'
CLIENT_ID = 'your_client_id'
SECRET_ID = 'your_secret_id'
csvFileName = 'r1_' + str(datetime.now().strftime("%m%d%Y%H%M")) + '.csv'
def main():
# Open the csv file
csv_file = open(csvFileName, mode='w', encoding='UTF8')
fieldnames = ['Property', 'Space', 'AP Name', 'AP Model','Serial Number', 'AP Status', 'Client Count']
writer = csv.writer(csv_file)
writer.writerow(fieldnames)
# Initialize R1 class and get JWT
r1 = R1_API_calls()
jwt = r1.getJWT(R1HOST, TENANT_ID, CLIENT_ID, SECRET_ID)['access_token']
#print('jwt:', jwt)
#brandDetails = r1.getBrandDetails(R1HOST, jwt)
#print('brand details:', brandDetails)
propertyList = r1.getProperties(R1HOST, jwt)['data']
# print('properties:', propertyList)
# Loop through each property, get the required values and write .csv file
for brandProperty in propertyList:
print (brandProperty['name'])
spaceList = r1.getVenues(R1HOST, brandProperty['id'], jwt)
for space in spaceList:
print(space['name'])
apList = r1.getAPsByVenueId(R1HOST, brandProperty['id'],
space['id'], jwt)
if len(apList) == 0:
writer.writerow([brandProperty['name'], space['name'], '', '',
'', '', ''])
for ap in apList:
print(ap['name'])
try:
apModel = ap['model']
except:
apModel = 'Never contacted cloud'
print(apModel)
print(ap['serialNumber'])
#print(ap['clientCount'])
#print(ap['state'])
writer.writerow([brandProperty['name'], space['name'],
ap['name'], apModel, ap['serialNumber'],
ap['state'], ap['clientCount']])
print()
# Close the csv file
csv_file.close()
print (csvFileName)
if __name__ == '__main__':
main()