-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump_users.py
executable file
·50 lines (40 loc) · 1.16 KB
/
dump_users.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
#!/usr/bin/env python3
from base64 import b64encode
from getpass import getpass
from requests import get
from os import getenv
from sys import exit
HADES_API_KEY = getenv('HADES_API_KEY')
if HADES_API_KEY is not None:
headers = {'Authorization': HADES_API_KEY}
else:
headers = {
'Credentials': b64encode(
str(
input('Enter your Hades username: ')
+ '|'
+ getpass(prompt='Enter your Hades password: ')
).encode()
)
}
headers['User-Agent'] = 'db-dump/1.0'
tables = (
get('https://hades.thescriptgroup.in/api/events', headers=headers).json().keys()
)
for table in tables:
params = {'table': table}
response = get(
'https://hades.thescriptgroup.in/api/users', headers=headers, params=params
)
if response.status_code != 200:
try:
print(response.json()['message'])
except:
print(response.text)
exit(1)
users = response.json()
with open(f'{table}.csv', 'w') as f:
for user in users:
for field in user.keys():
f.write(f'{user[field]},')
f.write('\n')