summaryrefslogtreecommitdiff
path: root/other/bootstrap_daemon/docker/get-nodes.py
diff options
context:
space:
mode:
Diffstat (limited to 'other/bootstrap_daemon/docker/get-nodes.py')
-rwxr-xr-x[-rw-r--r--]other/bootstrap_daemon/docker/get-nodes.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/other/bootstrap_daemon/docker/get-nodes.py b/other/bootstrap_daemon/docker/get-nodes.py
index 821f089a..f38bd492 100644..100755
--- a/other/bootstrap_daemon/docker/get-nodes.py
+++ b/other/bootstrap_daemon/docker/get-nodes.py
@@ -24,26 +24,32 @@ THE SOFTWARE.
24# Gets a list of nodes from https://nodes.tox.chat/json and prints them out 24# Gets a list of nodes from https://nodes.tox.chat/json and prints them out
25# in the format of tox-bootstrapd config file. 25# in the format of tox-bootstrapd config file.
26 26
27import urllib.request
28import json 27import json
28import sys
29import urllib.request
29 30
30response = urllib.request.urlopen('https://nodes.tox.chat/json') 31response = urllib.request.urlopen('https://nodes.tox.chat/json')
31raw_json = response.read().decode('ascii', 'ignore') 32raw_json = response.read().decode('ascii', 'ignore')
32nodes = json.loads(raw_json)['nodes'] 33nodes = json.loads(raw_json)['nodes']
33 34
34output = 'bootstrap_nodes = (\n' 35def node_to_string(node):
35
36for node in nodes:
37 node_output = ' { // ' + node['maintainer'] + '\n' 36 node_output = ' { // ' + node['maintainer'] + '\n'
38 node_output += ' public_key = "' + node['public_key'] + '"\n' 37 node_output += ' public_key = "' + node['public_key'] + '"\n'
39 node_output += ' port = ' + str(node['port']) + '\n' 38 node_output += ' port = ' + str(node['port']) + '\n'
40 node_output += ' address = "' 39 node_output += ' address = "'
41 if len(node['ipv4']) > 4: 40 if len(node['ipv4']) > 4:
42 output += node_output + node['ipv4'] + '"\n },\n' 41 return node_output + node['ipv4'] + '"\n }'
43 if len(node['ipv6']) > 4: 42 if len(node['ipv6']) > 4:
44 output += node_output + node['ipv6'] + '"\n },\n' 43 return node_output + node['ipv6'] + '"\n }'
45 44 raise Exception('no IP address found for node ' + json.dumps(node))
46# remove last comma 45
47output = output[:-2] + '\n)\n' 46output = ('bootstrap_nodes = (\n' +
48 47 ',\n'.join(map(node_to_string, nodes)) +
49print(output) 48 '\n)')
49
50if len(sys.argv) > 1:
51 with open(sys.argv[1], 'a') as fh:
52 fh.write(output + '\n')
53 print("Wrote %d nodes to %s" % (len(nodes), sys.argv[1]))
54else:
55 print(output)