-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpythoncsvtest.py
68 lines (58 loc) · 2.23 KB
/
pythoncsvtest.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
import requests
from akamai.edgegrid import EdgeRc, EdgeGridAuth
import pandas as pd
session = requests.Session()
edgerc = EdgeRc('~/.edgerc')
section = 'default'
hostname = edgerc.get(section, 'host')
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
csvfile = ("/home/aaron/BOTMANPROJECT/FILES/ResourcesNames.csv")
df = pd.read_csv(csvfile)
print(df)
row, col = df.shape
Loop_limit = (row)
with open('/home/aaron/BOTMANPROJECT/FILES/OPERATORIDS.txt', 'w') as f:
for row_counter in range(Loop_limit):
resourcename = (df.iloc[row_counter,1])
resourcemethod = (df.iloc[row_counter,0])
resourcepath = (df.iloc[row_counter,2])
resourcepurpose = (df.iloc[row_counter,3])
CreateAPIResource = {
"apiResourceMethods": [
{
"apiResourceMethod": (resourcemethod)
}
],
"apiResourceName": (resourcename),
"description": "Created with API call",
"resourcePath": (resourcepath)
}
print(CreateAPIResource)
payload = CreateAPIResource
params = {
'accountSwitchKey':'B-F-F2JX4L:1-8BYUX'
}
response = session.post('https://' + hostname + '/api-definitions/v2/endpoints/845900/versions/16/resources', json=payload, params=params)
jsonresponse = response.json()
print(jsonresponse)
apiresourceid = (jsonresponse['apiResourceId'])
print(apiresourceid)
CreateAPIOperator = {
"method": (resourcemethod),
"operationPurpose": (resourcepurpose),
"apiResourceId": (apiresourceid),
"operationName": (resourcename),
"apiResourceId": (apiresourceid),
"operationName": (resourcename)
}
print(CreateAPIOperator)
apiresourceid_as_a_str = str(apiresourceid)
Path = '/api-definitions/v2/endpoints/845900/versions/16/resources/' + apiresourceid_as_a_str + '/operations'
print (Path)
payload = CreateAPIOperator
response = session.post('https://' + hostname + Path, json=payload, params=params)
jsonresponse = response.json()
print(jsonresponse)
operatorid = (jsonresponse['operationId'])
print(operatorid)
f.write("%s\n" % operatorid)