[TASK] import firstseen (#47)
This commit is contained in:
parent
c4d8fbd4df
commit
b131fac626
|
@ -50,7 +50,7 @@ For `nodes_path` and `graph_path` should be under the same folder for a meshview
|
||||||
|
|
||||||
### Service
|
### Service
|
||||||
```bash
|
```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 daemon-reload
|
||||||
systemctl start yanic
|
systemctl start yanic
|
||||||
systemctl enable yanic
|
systemctl enable yanic
|
||||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue