-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGetUsersWithSkipLimit.py
More file actions
60 lines (40 loc) · 1.57 KB
/
GetUsersWithSkipLimit.py
File metadata and controls
60 lines (40 loc) · 1.57 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
import requests
import json
import sys
import sqlite3
requests.packages.urllib3.disable_warnings() # Disable warning message
url = "https://198.18.133.254/api/relation/HcsUserREL/"
headers = {
'Authorization': "Basic '64encodedathentication'",
'Cache-Control': "no-cache",
'Postman-Token': "953e9c63-e753-40de-93b3-ee6d09eb6400"
}
##print(response.text)
conn = sqlite3.connect('sqlite_file.db')
c = conn.cursor()
c.execute('''CREATE TABLE if not exists usersdata
(ID INTEGER PRIMARY KEY NULL,
username TEXT NOT NULL,
EP TEXT);''')
querystring = {"skip": "0", "limit" : "100"}
try:
response = requests.request("GET", url, headers=headers, params=querystring, verify=False)
except requests.exceptions.RequestException as _err:
print ( "Error processing API request", _err )
sys.exit(1)
usersJSONdump = response.json()
for u in (usersJSONdump['resources']):
_user_href = (u['meta']['references']['self'][0]['href'] )
_url2 = "https://198.18.133.254" + _user_href
response2 = requests.request("GET", _url2, cookies=response.cookies, verify=False)
userInfo = response2.json()
_EP = (userInfo['data']['ps']['entitlement_profile'])
_username = (userInfo['data']['username'])
print(_username)
print(_EP)
c.execute("insert into usersdata (username, EP) values (?,?)", (_username, _EP))
c.close()
c.execute('SELECT * FROM usersdata ')
print(c.fetchall())
#with open('importedusers_by_API.json', 'a') as usersFile:
#json.dump(usersJSONdump, usersFile, indent=4)