From 83f98d72856b197325dd2d3f6877fe156c02da9b Mon Sep 17 00:00:00 2001 From: Jerry Date: Fri, 1 May 2020 15:45:25 +0800 Subject: [PATCH] adjust json format --- .github/workflows/roa.yml | 2 ++ scripts/roa.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/roa.yml b/.github/workflows/roa.yml index 7579263..cfe8d89 100644 --- a/.github/workflows/roa.yml +++ b/.github/workflows/roa.yml @@ -5,6 +5,8 @@ name: roa_generator on: push: branches: [ master ] + schedule: + - cron: '0 6 * * 1' jobs: build: diff --git a/scripts/roa.py b/scripts/roa.py index 3d56a7b..091f25d 100755 --- a/scripts/roa.py +++ b/scripts/roa.py @@ -70,7 +70,7 @@ def route2roa(dirname, is_ipv6=False): if __name__ == "__main__": import argparse parser = argparse.ArgumentParser(description='NeoNetwork ROA tool') - parser.add_argument('-m', '--max', type=int, default=30, help='set ipv4 max prefix length') + parser.add_argument('-m', '--max', type=int, default=29, help='set ipv4 max prefix length') parser.add_argument('-M', '--max6', type=int, default=64, help='set ipv6 max prefix length') parser.add_argument('-j', '--json', action='store_true', help='output json') parser.add_argument('-o', '--output', default='', help='write output to file') @@ -104,12 +104,15 @@ if __name__ == "__main__": output = "" if args.json: - import json - d_output = dict() + import json, time + for r in (*roa4, *roa6): + r[0] = "AS%d" % r[0] + current = int(time.time()) + d_output = {"metadata": {"counts": len(roa4)+len(roa6), "generated": current, "valid": current+14*86400}, "roas": list()} for r in roa4: - d_output.setdefault('ipv4', list()).append(dict(zip(['asn', 'prefix', 'max'], r))) + d_output['roas'].append(dict(zip(['asn', 'prefix', 'maxLength'], r))) for r in roa6: - d_output.setdefault('ipv6', list()).append(dict(zip(['asn', 'prefix', 'max'], r))) + d_output['roas'].append(dict(zip(['asn', 'prefix', 'maxLength'], r))) output = json.dumps(d_output, indent=2) else: output += "# NeoNetwork ROA tool\n"