diff options
Diffstat (limited to 'other/bootstrap_daemon/docker/get-nodes.py')
-rwxr-xr-x[-rw-r--r--] | other/bootstrap_daemon/docker/get-nodes.py | 28 |
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 | ||
27 | import urllib.request | ||
28 | import json | 27 | import json |
28 | import sys | ||
29 | import urllib.request | ||
29 | 30 | ||
30 | response = urllib.request.urlopen('https://nodes.tox.chat/json') | 31 | response = urllib.request.urlopen('https://nodes.tox.chat/json') |
31 | raw_json = response.read().decode('ascii', 'ignore') | 32 | raw_json = response.read().decode('ascii', 'ignore') |
32 | nodes = json.loads(raw_json)['nodes'] | 33 | nodes = json.loads(raw_json)['nodes'] |
33 | 34 | ||
34 | output = 'bootstrap_nodes = (\n' | 35 | def node_to_string(node): |
35 | |||
36 | for 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 | |
47 | output = output[:-2] + '\n)\n' | 46 | output = ('bootstrap_nodes = (\n' + |
48 | 47 | ',\n'.join(map(node_to_string, nodes)) + | |
49 | print(output) | 48 | '\n)') |
49 | |||
50 | if 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])) | ||
54 | else: | ||
55 | print(output) | ||