-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapis.py
197 lines (165 loc) · 6.82 KB
/
apis.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
from requests import get, post, put, delete, patch
from datetime import datetime
from time import sleep
#from . import exceptions
"""Honeygain APIs
This tool is designed to integrate Honeygain's
web hook APIs with Python.
With this API, we hope to improve code-writing
efficiency.
The main difference between this API and the
web hooks is that the returned results are
parsed for Python use.
If you have any tips, suggestions, comments,
or questions, please DM me on Discord
@idontknow#4073.
"""
def create_user(email:str, password:str, coupon:str = ""):
"""Creates a new Honeygain user"""
request_data = post(
"https://dashboard.honeygain.com/api/v1/users",
json={
'email': email,
'password': password,
'coupon': coupon
}
).json()['data']
return request_data
def gen_authcode(email:str, password:str):
"""Requests an authorization token used in the header from Honeygain"""
requestdata = post(
"https://dashboard.honeygain.com/api/v1/users/tokens",
json={
'email': email,
'password': password
}
).json()['data']
return requestdata
def fetch_aboutme(authtoken:str):
"""Fetches information about the current user."""
requestdata = get(
"https://dashboard.honeygain.com/api/v1/users/me",
headers={'authorization': ("Bearer " + authtoken)}
).json()['data']
requestdata['created_at'] = datetime.strptime(requestdata['created_at'].replace('+00:00', 'Z'), "%Y-%m-%dT%H:%M:%SZ")
return requestdata
def fetch_tosstatus(authtoken:str):
"""Fetches information about the current user's terms of service status."""
requestdata = get(
"https://dashboard.honeygain.com/api/v1/users/tos",
headers={'authorization': ("Bearer " + authtoken)}
).json()['data']
return requestdata
def fetch_trafficstats(authtoken:str):
"""Fetches information about traffic."""
requestdata = get(
"https://dashboard.honeygain.com/api/v1/dashboards/traffic_stats",
headers={'authorization': ("Bearer " + authtoken)}
).json()['data']
for entry in requestdata['traffic_stats']:
entry['date'] = datetime.strptime(entry['date'], "%Y-%m-%d")
return requestdata
def fetch_balances(authtoken:str):
"""Fetches information about the current user's balances."""
requestdata = get(
"https://dashboard.honeygain.com/api/v1/users/balances",
headers={'authorization': ("Bearer " + authtoken)}
).json()['data']
return requestdata
def fetch_devices(authtoken:str, deleted:bool=False):
"""Fetches information about the devices and their respective traffic."""
if deleted == False:
appendix = '?'
elif deleted == True:
appendix = '?deleted=true&'
devicelist=[]
request = get(
"https://dashboard.honeygain.com/api/v1/devices%s" % appendix,
headers={'authorization': ("Bearer " + authtoken)}
).json()
for device in request['data']:
devicelist.append(device)
while request['meta']['pagination']['current_page'] < request['meta']['pagination']['total_pages']:
request = get(
"https://dashboard.honeygain.com/api/v1/devices%spage=%i" % (appendix, (request['meta']['pagination']['current_page'] + 1)),
headers={'authorization': ("Bearer " + authtoken)}
).json()
for device in request['data']:
devicelist.append(device)
return devicelist
def fetch_referrals(authtoken:str):
"""Fetches information about the user's referrals."""
referrallist=[]
request = get(
"https://dashboard.honeygain.com/api/v1/referrals?page=1",
headers={'authorization': ("Bearer " + authtoken)}
).json()
for referral in request['data']:
referrallist.append(referral)
while request['meta']['pagination']['current_page'] < request['meta']['pagination']['total_pages']:
request = get(
"https://dashboard.honeygain.com/api/v1/referrals?page=%i" % ((request['meta']['pagination']['current_page'] + 1)),
headers={'authorization': ("Bearer " + authtoken)}
).json()
for referral in request['data']:
referrallist.append(referral)
return referrallist
def fetch_transactions(authtoken:str):
"""Fetches information about the user's transactions."""
transactionlist=[]
request = get(
"https://dashboard.honeygain.com/api/v1/transactions?page=1",
headers={'authorization': ("Bearer " + authtoken)}
).json()
for transaction in request['data']:
transaction['booked_at'] = datetime.strptime(transaction['booked_at'], "%Y-%m-%d %H:%M:%S")
transaction['created_at'] = datetime.strptime(transaction['created_at'], "%Y-%m-%d %H:%M:%S")
transactionlist.append(transaction)
while request['meta']['pagination']['current_page'] < request['meta']['pagination']['total_pages']:
request = get(
"https://dashboard.honeygain.com/api/v1/transactions?page=%i" % ((request['meta']['pagination']['current_page'] + 1)),
headers={'authorization': ("Bearer " + authtoken)}
).json()
for transaction in request['data']:
transaction['booked_at'] = datetime.strptime(transaction['booked_at'], "%Y-%m-%d %H:%M:%S")
transaction['created_at'] = datetime.strptime(transaction['created_at'], "%Y-%m-%d %H:%M:%S")
transactionlist.append(transaction)
return transactionlist
def chg_password(authtoken:str, currentPassword:str, newPassword:str):
"""Changes the password of the current user."""
request = put(
"https://dashboard.honeygain.com/api/v1/users/passwords",
headers={'authorization': ("Bearer " + authtoken)},
json={
'current_password': currentPassword,
'new_password': newPassword
}
)
return request.status_code
def chg_devicename(authtoken:str, deviceID:str, newname:str):
"""Changes a device's name as recognized by Honeygain."""
request = put(
"https://dashboard.honeygain.com/api/v1/devices/%s/titles" % deviceID,
headers={'authorization': ("Bearer " + authtoken)},
json={
'title': newname
}
)
return request.status_code
def del_device(authtoken:str, deviceID:str):
"""Deletes a device (ie. move it into Removed Devices)."""
request = delete(
"https://dashboard.honeygain.com/api/v1/devices/%s" % deviceID,
headers={'authorization': ("Bearer " + authtoken)}
)
return request.status_code
def res_device(authtoken:str, deviceID:str):
"""Restores a device from Removed Devices."""
request = patch(
"https://dashboard.honeygain.com/api/v1/devices/%s" % deviceID,
headers={'authorization': ("Bearer " + authtoken)},
json={
'deleted': False
}
)
return request.status_code