-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbest_hive_nodes.py
37 lines (27 loc) · 944 Bytes
/
best_hive_nodes.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
import requests
from tenacity import retry, stop_after_attempt, wait_exponential
BECON_URL = 'https://beacon.peakd.com/api/best'
DEFAULT_NODES = ['https://api.hive.blog',
'https://api.openhive.network',
'https://anyx.io',
'api.deathwing.me']
def return_default_nodes(message):
print(message)
return DEFAULT_NODES
@retry(stop=stop_after_attempt(5),
wait=wait_exponential(multiplier=1, min=0.5, max=5),
retry_error_callback=return_default_nodes)
def get_best_hive_nodes(score=90):
node_list = requests.get(BECON_URL)
return find_best_nodes(node_list.json(), score)
def find_best_nodes(node_list, score):
nodes = []
all_nodes = []
for node in node_list:
all_nodes.append(node['endpoint'])
if node['score'] > score:
nodes.append(node['endpoint'])
if nodes:
return nodes
else:
return all_nodes