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')
-rw-r--r--other/bootstrap_daemon/docker/get-nodes.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/other/bootstrap_daemon/docker/get-nodes.py b/other/bootstrap_daemon/docker/get-nodes.py
new file mode 100644
index 00000000..9a284748
--- /dev/null
+++ b/other/bootstrap_daemon/docker/get-nodes.py
@@ -0,0 +1,49 @@
1#!/usr/bin/env python3
2"""
3Copyright (c) 2016 by nurupo <nurupo.contributions@gmail.com>
4
5Permission is hereby granted, free of charge, to any person obtaining a copy
6of this software and associated documentation files (the "Software"), to deal
7in the Software without restriction, including without limitation the rights
8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9copies of the Software, and to permit persons to whom the Software is
10furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21THE SOFTWARE.
22"""
23
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.
26
27import urllib.request
28import json
29
30response = urllib.request.urlopen('https://nodes.tox.chat/json')
31raw_json = response.read().decode('ascii', 'ignore')
32nodes = json.loads(raw_json)['nodes']
33
34output = 'bootstrap_nodes = ('
35
36for node in nodes:
37 node_output = ' { // ' + node['maintainer'] + '\n'
38 node_output += ' public_key = "' + node['public_key'] + '"\n'
39 node_output += ' port = ' + str(node['port']) + '\n'
40 node_output += ' address = "'
41 if len(node['ipv4']) > 4:
42 output += node_output + node['ipv4'] + '"\n },\n'
43 if len(node['ipv6']) > 4:
44 output += node_output + node['ipv6'] + '"\n },\n'
45
46# remove last comma
47output = output[:-2] + '\n)\n'
48
49print(output)