-
Notifications
You must be signed in to change notification settings - Fork 0
/
hiveapi.py
89 lines (79 loc) · 2.38 KB
/
hiveapi.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
import requests
import json
import PyPDF2
import os
uri = 'https://api2.hiveos.farm/api/v2'
contype = "application/json"
dirname = os.path.dirname(__file__)
filename = os.path.join(dirname, 'Json/hive.json')
config = json.load(open(filename))
token = 'Bearer ' + config["token"]
def account():
url = "{}/account".format(uri)
payload = {}
headers = {
"Content-Type": contype,
'Authorization': token
}
response = requests.request("GET", url, headers=headers, params=payload)
return json.loads(response.text)
def get_power_consumption(date):
date = str(date)
url = "{}/farms/1699672/power_report".format(uri)
payload = {
"date": date,
"period": "1d",
"action": "download"
}
headers = {
"Content-Type": contype,
'Authorization': token
}
response = requests.request("GET", url, headers=headers, params=payload)
if response.status_code == 200:
dirname = os.path.dirname(__file__)
# windows \\ linux /
filename = os.path.join(dirname, 'PDF\\metadata.pdf')
with open(filename, 'wb') as f:
f.write(response.content)
f.close
temp = open(filename, 'rb')
print(temp)
pdf = PyPDF2.PdfFileReader(temp)
first_page = pdf.getPage(0)
text = first_page.extractText()
split1 = text.split("ion: ")
split2 = split1[1].split("Y")
temp.close
return split2[0]
else:
return -1
def test():
url = "https://api2.hiveos.farm/api/v2/farms/1699672/metrics"
payload = {}
headers = {
"Content-Type": contype,
'Authorization': token
}
response = requests.request("GET", url, headers=headers, params=payload)
return json.loads(response.text)
def get_hashrates():
#get workers
url = "{}/farms/1699672/stats".format(uri)
payload = {}
headers = {
"Content-Type": contype,
'Authorization': token
}
response = requests.request("GET", url, headers=headers, params=payload)
return json.loads(response.text)["hashrates"]
def get_farm_stats():
#get workers
url = "{}/farms/1699672/stats".format(uri)
payload = {}
headers = {
"Content-Type": contype,
'Authorization': token
}
response = requests.request("GET", url, headers=headers, params=payload)
return json.loads(response.text)["stats"]