Created
February 24, 2018 22:25
-
-
Save polymorphm/3dc497740c9b72757ad1abf1aa974ccd to your computer and use it in GitHub Desktop.
script to fetch all peers from https://github.com/hyperboria/peers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- mode: python; coding: utf-8 -*- | |
import sys | |
import os, os.path | |
import json | |
def main(): | |
# the path to cloned directory https://github.com/hyperboria/peers | |
peer_dir_path = sys.argv[1] | |
# exclude peer name list | |
exclude_name_list = sys.argv[2:] | |
for is_ipv6 in (False, True): | |
if is_ipv6: | |
print('// *** IPv6 ***\n//') | |
else: | |
print('// *** IPv4 ***\n//') | |
for root, dirs, files in os.walk(peer_dir_path): | |
for name in files: | |
if not name.endswith('.k'): | |
continue | |
path = os.path.join(root, name) | |
with open(path, encoding='utf-8') as fd: | |
data = json.loads(fd.read()) | |
if not isinstance(data, dict): | |
raise ValueError('not isinstance(data, dict): {!r}'.format(data)) | |
for k in data: | |
if is_ipv6 and '[' not in k \ | |
or not is_ipv6 and '[' in k: | |
continue | |
v = data[k] | |
if v.get('peerName') in exclude_name_list: | |
continue | |
print('// {}\n{}: {{'.format(path, json.dumps(k))) | |
for kk in v: | |
vv = v[kk] | |
print('{}{}: {},'.format(' ' * 4, json.dumps(kk), json.dumps(vv))) | |
print('},') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment