Under construction!


In [1]:
import requests
import json

# Basic Setup
PORT_NUMBER = 1234
BASE = 'http://localhost:' + str(PORT_NUMBER) + '/v1/'

# Header for posting data to the server as JSON
HEADERS = {'Content-Type': 'application/json'}

In [59]:
res = requests.get(BASE + 'networks?format=SUID')
suid_list = json.loads(res.content)
net_suid = suid_list[0]
res_net = requests.get(BASE + 'networks/' + str(net_suid))

metro_net = json.loads(res_net.content)
nodes = metro_net['elements']['nodes']

In [60]:
# Create group
groups = {}
group_names = {}

for node in nodes:
    group_id = node['data']['station_g_cd']
    suid = node['data']['SUID']
    
    if group_id in groups.keys():
        current_list = groups[group_id]
        current_list.append(suid)
        groups[group_id] = current_list
    else:
        new_list = [suid]
        groups[group_id] = new_list
        group_names[group_id] = node['data']['station_name']

for key in groups.keys():
    group = groups[key]
    group_name = group_names[key]
    if len(group) is 1:
        continue
    else:
        #create Group
        group_data = {'name': group_name,'nodes': group,'edges': []}
        res1 = requests.post(BASE + 'networks/' + str(net_suid) + '/groups', data=json.dumps(group_data), headers=HEADERS)
        group_res = json.loads(res1.content)

In [61]:
all_groups = requests.get(BASE + 'networks/' + str(net_suid) + '/groups')
allgp = json.loads(all_groups.content)

for g in allgp:
    requests.get(BASE + 'networks/' + str(net_suid) + '/groups/' + str(g['SUID']) + '/collapse')

In [62]:
res1 = requests.delete(BASE + 'networks/' + str(net_suid) + '/groups')