-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRead_File.py
98 lines (65 loc) · 2.51 KB
/
Read_File.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
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
import boto3
import xlrd
from xlrd.book import open_workbook_xls
def read_xls(bucketName,filePath):
# Read File From S3 Bucket
s3Client = boto3.client('s3')
data = s3Client.get_object(Bucket=bucketName, Key=filePath)
content = data['Body'].read()
# Read xls File for API-Gateway Detail
workbook = open_workbook_xls(file_contents=content)
return workbook
def read_api_detail(workbook):
data = {}
sheet1 = workbook.sheet_by_index(0)
data['APIGW_Name'] = sheet1.cell_value(0,1).strip()
data['APIGW_Des'] = sheet1.cell_value(1,1).strip()
data['Connection_Type'] = sheet1.cell_value(2,1).strip()
data['VPC_Name'] = sheet1.cell_value(3,1).strip()
data['Stage_Name'] = sheet1.cell_value(4,1).strip()
data['Deployment_Name'] = sheet1.cell_value(5,1).strip()
data['Header_Required'] = sheet1.cell_value(8,1).strip()
data['EndPointConfig'] = sheet1.cell_value(10,1).strip()
data['APIKeySource'] = sheet1.cell_value(11,1).strip()
ResponseList = []
index = 1
while index < sheet1.ncols :
ResponseList.append(sheet1.cell_value(9,index).strip())
index = index + 1
data['GWResponse'] = ResponseList
HeaderList = []
index = 1
while index < sheet1.ncols :
HeaderList.append(sheet1.cell_value(6,index).strip())
index = index + 1
data['Headers'] = HeaderList
MethodHeaderList = []
index = 1
while index < sheet1.ncols :
try:
MethodHeaderList.append(sheet1.cell_value(7,index).strip())
index = index + 1
except:
print('')
data['Method_Header'] = MethodHeaderList
#print(data)
return data
def read_Resource_Method_detail(workbook):
data = []
sheet2 = workbook.sheet_by_index(1)
TotalRows = sheet2.nrows
index = 1
while index < TotalRows:
row = {}
try:
row['RootResourceName'] = sheet2.cell_value(index,0)
if len(row['RootResourceName']) < 1 :
row['RootResourceName'] = '/'
except:
row['RootResourceName'] = '/'
row['SubResourceNameList'] = sheet2.cell_value(index,1).split('/')
row['MethodType'] = sheet2.cell_value(index,2)
row['EndPointURL'] = sheet2.cell_value(index,3)
data.append(row)
index = index + 1
return data