{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Under construction!" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import requests\n", "import json\n", "\n", "# Basic Setup\n", "PORT_NUMBER = 1234\n", "BASE = 'http://localhost:' + str(PORT_NUMBER) + '/v1/'\n", "\n", "# Header for posting data to the server as JSON\n", "HEADERS = {'Content-Type': 'application/json'}" ] }, { "cell_type": "code", "execution_count": 59, "metadata": { "collapsed": false }, "outputs": [], "source": [ "res = requests.get(BASE + 'networks?format=SUID')\n", "suid_list = json.loads(res.content)\n", "net_suid = suid_list[0]\n", "res_net = requests.get(BASE + 'networks/' + str(net_suid))\n", "\n", "metro_net = json.loads(res_net.content)\n", "nodes = metro_net['elements']['nodes']" ] }, { "cell_type": "code", "execution_count": 60, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Create group\n", "groups = {}\n", "group_names = {}\n", "\n", "for node in nodes:\n", " group_id = node['data']['station_g_cd']\n", " suid = node['data']['SUID']\n", " \n", " if group_id in groups.keys():\n", " current_list = groups[group_id]\n", " current_list.append(suid)\n", " groups[group_id] = current_list\n", " else:\n", " new_list = [suid]\n", " groups[group_id] = new_list\n", " group_names[group_id] = node['data']['station_name']\n", "\n", "for key in groups.keys():\n", " group = groups[key]\n", " group_name = group_names[key]\n", " if len(group) is 1:\n", " continue\n", " else:\n", " #create Group\n", " group_data = {'name': group_name,'nodes': group,'edges': []}\n", " res1 = requests.post(BASE + 'networks/' + str(net_suid) + '/groups', data=json.dumps(group_data), headers=HEADERS)\n", " group_res = json.loads(res1.content)\n", "\n", " " ] }, { "cell_type": "code", "execution_count": 61, "metadata": { "collapsed": false }, "outputs": [], "source": [ "all_groups = requests.get(BASE + 'networks/' + str(net_suid) + '/groups')\n", "allgp = json.loads(all_groups.content)\n", "\n", "for g in allgp:\n", " requests.get(BASE + 'networks/' + str(net_suid) + '/groups/' + str(g['SUID']) + '/collapse')" ] }, { "cell_type": "code", "execution_count": 62, "metadata": { "collapsed": false }, "outputs": [], "source": [ "res1 = requests.delete(BASE + 'networks/' + str(net_suid) + '/groups')\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 0 }