Created
September 5, 2015 14:00
-
-
Save mweinelt/c50c13b927ba27d698f6 to your computer and use it in GitHub Desktop.
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/env python3 | |
import json | |
import sys | |
infile = sys.argv[1] | |
with open(infile) as handle: | |
nodeinfo = json.load(handle) | |
for mac in nodeinfo: | |
try: | |
del nodeinfo[mac]['owner'] | |
except KeyError: | |
pass | |
print(json.dumps(nodeinfo, indent=2)) |
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
#!/bin/sh | |
BASEDIR=$(dirname $0) | |
cd $BASEDIR | |
API_BASEDIR=/srv/www/api/alfred | |
CHMOD=644 | |
NODEINFO=$API_BASEDIR/nodeinfo.json | |
STATISTICS=$API_BASEDIR/statistics.json | |
NEIGHBOURS=$API_BASEDIR/neighbours.json | |
NODEINFO_AND_STATISTICS=$API_BASEDIR/nodeinfo-statistics.json | |
# remove owner information before exposing nodeinfo | |
TMPFILE=$(mktemp) | |
ANONYMIZED=$(mktemp) | |
chmod $CHMOD $ANONYMIZED | |
alfred-json -r 158 -f json -z > $TMPFILE | |
$BASEDIR/anonymize $TMPFILE > $ANONYMIZED | |
mv $ANONYMIZED $NODEINFO | |
rm $TMPFILE | |
TMPFILE=$(mktemp) | |
chmod $CHMOD $TMPFILE | |
alfred-json -r 159 -f json -z > $TMPFILE | |
mv $TMPFILE $STATISTICS | |
TMPFILE=$(mktemp) | |
chmod $CHMOD $TMPFILE | |
alfred-json -r 160 -f json -z > $TMPFILE | |
mv $TMPFILE $NEIGHBOURS | |
TMPFILE=$(mktemp) | |
chmod $CHMOD $TMPFILE | |
$BASEDIR/merge $NODEINFO $STATISTICS $TMPFILE | |
mv $TMPFILE $NODEINFO_AND_STATISTICS |
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/env python3 | |
import json | |
import sys | |
import time | |
if len(sys.argv) < 3: | |
print("merge <nodeinfo.json> <statistics.json> <target file>", file=sys.stderr) | |
sys.exit(1) | |
nodeinfo_path = sys.argv[1] | |
statistics_path = sys.argv[2] | |
target_path = sys.argv[3] | |
with open(nodeinfo_path, "r") as handle: | |
nodeinfo = json.load(handle) | |
with open(statistics_path, "r") as handle: | |
statistics = json.load(handle) | |
# merge | |
for k in nodeinfo: | |
if k in statistics: | |
nodeinfo[k].update(statistics[k]) | |
else: | |
try: | |
nodeinfo[k] = statistics[k] | |
except KeyError: | |
print('unable to merge node {}'.format(k), file=sys.stderr) | |
pass | |
with open(target_path, "w") as handle: | |
handle.write(json.dumps({"updated": int(time.time()), "nodes": nodeinfo}, indent=2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment