Import and save locations of bikeshare stations


In [6]:
import pickle
import xml.etree.ElementTree as ET
import urllib.request

Import Capital Bikeshare station information .xml file


In [7]:
xml_path = 'https://feeds.capitalbikeshare.com/stations/stations.xml'
tree = ET.parse(urllib.request.urlopen(xml_path))
root = tree.getroot()

create dictionary of bikeshare station (key) and its location (value)
be sure to convert location data into floats


In [11]:
station_location = dict()

for child in root:
    tmp_lst = [float(child[4].text),  float(child[5].text)]
    station_location[child[1].text] = tmp_lst

station_location['10th & E St NW']


Out[11]:
[38.895914, -77.026064]

save dictionary of bikeshare stations to pickle file


In [12]:
pickle.dump( station_location, open( "bike_location.p", "wb" ) )

In [ ]: