Skip to content

Commit

Permalink
[TASK] import firstseen (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire authored and corny committed Mar 26, 2017
1 parent c4d8fbd commit b131fac
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
44 changes: 44 additions & 0 deletions contrib/yanic-import-timestamp
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b131fac

Please sign in to comment.