diff --git a/INSTALL.md b/INSTALL.md index 3358e0b..cc541e0 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -50,7 +50,7 @@ For `nodes_path` and `graph_path` should be under the same folder for a meshview ### Service ```bash -cp /opt/go/src/github.com/FreifunkBremen/yanic/init/linux-systemd/yanic.service /lib/systemd/system +cp /opt/go/src/github.com/FreifunkBremen/yanic/contrib/init/linux-systemd/yanic.service /lib/systemd/system/ systemctl daemon-reload systemctl start yanic systemctl enable yanic diff --git a/init/linux-systemd/yanic.service b/contrib/init/linux-systemd/yanic.service similarity index 100% rename from init/linux-systemd/yanic.service rename to contrib/init/linux-systemd/yanic.service diff --git a/contrib/yanic-import-timestamp b/contrib/yanic-import-timestamp new file mode 100755 index 0000000..4305877 --- /dev/null +++ b/contrib/yanic-import-timestamp @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +import json +import argparse +import os +import sys + +parser = argparse.ArgumentParser() + +parser.add_argument('-n', '--nodesjson', action='store', + help='old nodes.json file you want to read firstseen from',required=True) + +parser.add_argument('-s', '--state', action='store', + help='state.json you want to store',required=True) + +args = parser.parse_args() +options = vars(args) + +oldnodes_fn = os.path.realpath(options['nodesjson']) +newnodes_fn = os.path.realpath(options['state']) + +with open(oldnodes_fn, 'r', encoding=('UTF-8')) as oldnodedb_handle: + oldnodedb = json.load(oldnodedb_handle) +with open(newnodes_fn, 'r', encoding=('UTF-8')) as newnodedb_handle: + newnodedb = json.load(newnodedb_handle) + +count = 0 +if oldnodedb['version'] == 1: + for nodeid, node in newnodedb['nodes'].items(): + for oldnodeid, oldnode in oldnodedb['nodes'].items(): + if oldnodeid == nodeid: + node['firstseen'] = "{}+0100".format(oldnode['firstseen']) + count+=1 + +if oldnodedb['version'] == 2: + for nodeid, node in newnodedb['nodes'].items(): + for oldnode in oldnodedb['nodes']: + if oldnode['nodeinfo']['node_id'] == nodeid: + node['firstseen'] = "{}+0100".format(oldnode['firstseen']) + count+=1 + +with open(newnodes_fn, 'w') as f: + json.dump(newnodedb, f) + +print('firstseen updated on %d nodes' % count)