Want more features on Pastebin? Sign Up, it's FREE!
Guest

cleanup_stops.py

By: asweigart on Feb 10th, 2014  |  syntax: Python  |  size: 2.52 KB  |  views: 60  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import munistops
  2.  
  3. # collect all routes to each stop
  4. stopsToRoutes = {}
  5. stopsFoundSoFar = []
  6. for route in munistops.munistops:
  7.     if route in ['1AX', '1BX', '5L', '8AX', '8BX', '9L', '14L', '14X', '28L', '31AX', '31BX', '38L', '38AX', '38BX', '71L', 'K OWL', 'L OWL', 'M OWL', 'N OWL', 'T OWL' '59', '60', '61', '30X', 'NX']:
  8.         continue # skip redundant routes
  9.     for stop in munistops.munistops[route]:
  10.         if stop['title'] in stopsFoundSoFar:
  11.             continue # don't have stops listed more than once (happens when, for example, inbound and outbound stops are at the same intersection)
  12.         stopsFoundSoFar.append(stop['title'])
  13.         stopsToRoutes.setdefault(stop['stopId'], {'lat':None, 'lon':None, 'title':None, 'routes':[]})
  14.         stopsToRoutes[stop['stopId']]['lat'] = stop['lat']
  15.         stopsToRoutes[stop['stopId']]['lon'] = stop['lon']
  16.         stopsToRoutes[stop['stopId']]['title'] = stop['title']
  17.         if route not in stopsToRoutes[stop['stopId']]['routes']:
  18.             stopsToRoutes[stop['stopId']]['routes'].append(route)
  19.  
  20. # compile the javascript code
  21. stopToRoutesJS = []
  22. for stopId in stopsToRoutes.keys():
  23.     stopInfo = stopsToRoutes[stopId]
  24.     stopToRoutesJS.append('"%s": {"lat": %s, "lon": %s, "title": "%s", "routes": %s}' % (stopId, stopInfo['lat'], stopInfo['lon'], stopInfo['title'], stopInfo['routes']))
  25.  
  26. # output javascript
  27. fo = open('stops_cleanedup.js', 'w')
  28. fo.write("""
  29. // Actually, you can just hover over the markers and a tool tip shows up, so I don't need the stopInfoWindow
  30. /*var stopInfoWindow = new google.maps.InfoWindow({
  31.    disableAutoPan: true
  32.    });*/
  33.  
  34. var stopsList = ["%s"];
  35. var stopsToRoutes = {%s};
  36. for (var i = 0; i < stopsList.length; i++) {
  37.    currentStopId = stopsList[i];
  38.    var marker = new google.maps.Marker({
  39.        position: new google.maps.LatLng(stopsToRoutes[currentStopId]['lat'], stopsToRoutes[currentStopId]['lon']),
  40.        map: map,
  41.        title: stopsToRoutes[currentStopId]['title']
  42.        });
  43.    /*(function(thisContent, thisMarker) { // making this into a closure so that "thisContent" keeps its value
  44.        google.maps.event.addListener(marker, 'click', function() {
  45.            stopInfoWindow.close();
  46.            stopInfoWindow.setContent(thisContent);
  47.            stopInfoWindow.open(map, thisMarker);
  48.            });
  49.    })(stopsToRoutes[currentStopId]['title'] + '<br />' + stopsToRoutes[currentStopId]['routes'].join(), marker);*/
  50. }
  51. """ % ('","'.join(stopsToRoutes.keys()),  ','.join(stopToRoutesJS)))
  52. fo.close()
clone this paste RAW Paste Data