-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHoneygain.py
122 lines (97 loc) · 4.61 KB
/
Honeygain.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
import json
import requests
"""
This Class is made to use the undocumented Honeygain API.
There are a few more things possible, like changing passwords or
rename devices, which are not implemented nor planned.
Their API is ratelimited and they will ban your account and IP if
you go over their limit. The limit is unknown but the webinterface does
11 initial requests and then fetches /users/balances every minute.
"""
class Honeygain():
def __init__(self, token=None, debug=False):
self.basueUrl = 'https://dashboard.honeygain.com/api'
self.token = token
self.userId = None
self.debug = debug
def login(self, email=None, password=None):
if email is None or password is None:
raise Exception("Email and password are required")
try:
req = requests.post("https://dashboard.honeygain.com/api/v1/users/tokens", json={'email': email,'password': password})
if req.status_code == 401:
raise Exception(req.json()['details'])
if req.status_code == 429:
raise Exception("RateLimit exceeded (probably)")
elif req.status_code != 200:
raise Exception("Unknown error")
self.token = req.json()['data']["access_token"]
except Exception as e:
raise Exception(e)
def __checkBearerToken(self):
if self.token == None:
raise Exception("No Bearer Token set. Call login() or set bearer token in constructor")
def __request(self, endpoint):
url = self.basueUrl + endpoint
if self.debug:
print("Requesting: " + url)
self.__checkBearerToken()
auth = "Bearer " + self.token
headers = {"Authorization": auth}
try:
r = requests.get(url, headers=headers).json()
except Exception as e:
raise Exception(e)
return r
def getBalance(self):
return self.__request("/v1/users/balances")
def getJumpTaskEarnings(self):
return self.__request("/v1/earnings/jt")
def getUser(self):
return self.__request("/v1/users/me")
def getUserDevices(self, page=1):
return self.__request("/v1/devices?page=" + str(page))
def getTosInfo(self):
return self.__request("/v1/users/tos")
def getMonthlyGatherings(self):
return self.__request("/v1/earnings/stats")
def getReferrals(self, page=1):
return self.__request("/v1/referrals?page=" + str(page))
def getReferralEarnings(self):
return self.__request("/v1/referrals/earnings")
def getTodaysEarnings(self):
return self.__request("/v1/earnings/today")
def getRegisteredDevices(self):
return self.__request("/v2/devices")
def getMonthlyWalletStats(self):
return self.__request("/v1/earnings/wallet-stats")
def getMonthlyTrafficStats(self):
return self.__request("/v1/dashboards/traffic_stats")
def getNotifications(self, page=1):
if self.userId is None:
self.userId = self.getUser()["data"]["id"]
return self.__request("/v1/notifications?user_id=" + self.userId)
# SEMI TESTED
def tryLuckyPot(self):
notifications = self.getNotifications()
if len(notifications["data"]) == 0:
return {"status": "Luckypot not available"}
for notification in notifications["data"]:
if notification["template"] == "lucky_pot":
self.__notification(notification["hash"], notification["campaign_id"], "triggered")
ret = self.__getWinnings().json()
if self.debug:
print("You have won " + str(ret["data"]["credits"]) + " credits!")
self.__notification(notification["hash"], notification["campaign_id"], "closed")
return ret
def __getWinnings(self):
self.__checkBearerToken()
r = requests.post(self.basueUrl+"/v1/contest_winnings", headers={"Authorization": "Bearer " + self.token})
if r.status_code not in [200]:
raise Exception("There was an error opening the honey jar, this may be because you've opened it today.")
return r
def __notification(self, notificationId, campaignId, action):
self.__checkBearerToken()
r = requests.post(self.basueUrl+"/v1/notifications/"+notificationId+"/actions", headers={"Authorization": "Bearer " + self.token}, json={"campaign_id":campaignId,"action":action,"user_id":self.userId})
if r.status_code not in [200,201]:
raise Exception("Error: could not work with notification. Action: " + action)