source: genesis/tools/merge-nodeplanner-json.py@ 14376

Last change on this file since 14376 was 14335, checked in by rick, 6 years ago

Add helper PoC to help merge nodeplanner data

How to use:

  • Export new nodeplanner data:

$ ./gformat.py create nodeplanner.json > nodeplanner-genesis.json

  • Export nodeplanner website data:

$ curl -s https://maps.wirelessleiden.nl/nodeplanner/api/get/state > nodeplanner-usermod.json

  • Merge files:

$ ./merge-nodeplanner-json.py nodeplanner-genesis.json nodeplanner-usermod.json > nodeplanner-new.json

  • Use importer function to upload data:

https://maps.wirelessleiden.nl/nodeplanner/

  • Check result
  • Use save function to save data:

https://maps.wirelessleiden.nl/nodeplanner/

  • Property svn:executable set to *
File size: 1002 bytes
RevLine 
[14335]1#!/usr/bin/env python3
2import datetime
3import json
4import os
5import socket
6import sys
7
8comment = 'Autogenerated by %s@%s at %s' % (os.environ.get('USER'), socket.gethostname(), datetime.datetime.today().isoformat())
9
10points_seens = []
11points = []
12links = []
13
14# Include auto-generated data
15data = json.load(open(sys.argv[1], 'r'))
16for point in data['points']:
17 if not point['name'] in points_seens:
18 points_seens.append(point['name'])
19 point['comment'] = comment
20 points.append(point)
21for link in data['links']:
22 link['comment'] = comment
23 links.append(link)
24
25
26# Filter out manual modifications
27data = json.load(open(sys.argv[2], 'r'))
28for point in data['points']:
29 if not point['name'] in points_seens:
30 if point['state'] in ['planned', 'wish']:
31 points.append(point)
32
33for link in data['links']:
34 if link['state'] in ['planned', 'wish']:
35 links.append(link)
36
37
38
39print(json.dumps({'points': points, 'links': links}, indent=2, sort_keys=True))
Note: See TracBrowser for help on using the repository browser.