@@ -0,0 +1,2184 @@
+%0A#Get Citibike station location data%0A%0A#url format:  https://feeds.citibikenyc.com/stations/stations.json%0A%0A%0Aimport json%0Aimport urllib%0Aimport codecs%0Aimport pandas as pd%0Aimport numpy as np%0A%0Acitibike_serviceurl =  %22https://feeds.citibikenyc.com/stations/stations.json%22%0A%0Awhile True:%0A%0A    url = citibike_serviceurl%0A    print 'Retrieving', url%0A%0A    data = urllib.urlopen(url).read()%0A    try:%0A        data_js = json.loads(str(data))%0A    except:%0A        data_js = None%0A        print '==Failure to Retrieve=='%0A        continue%0A%0A    #fhand = codecs.open('citibike_loc_json.js', 'w', %22utf-8%22)   #create a json file to inspect the format and content%0A    #fhand.writelines(json.dumps(data_js, indent=4))%0A%0A    fname = 'citibike_station_info.csv'%0A    fh_cb = open(fname, 'w+')%0A    fh_cb.writelines('Station_id,Station_Name,Location,Latitude,Longitude,Total_Docks,Available_Docks,Available_Bikes,lastCommunicationTime,Status,Test_Station,Status_Key')%0A%0A    all_station_info = data_js%5B'stationBeanList'%5D%0A    for station in all_station_info:%0A        cb_station_id = station%5B'id'%5D%0A        cb_station_name = station%5B'stationName'%5D%0A        cb_location = station%5B'stAddress1'%5D%0A        lat = station%5B'latitude'%5D%0A        lon = station%5B'longitude'%5D%0A%0A        tot_docks = station%5B%22totalDocks%22%5D%0A        avb_docks = station%5B'availableDocks'%5D%0A        avb_bikes = station%5B'availableBikes'%5D%0A        last_commu_time = station%5B'lastCommunicationTime'%5D%0A        status = station%5B'statusValue'%5D    # %22In Service%22%0A        is_test_station = station%5B'testStation'%5D%0A        status_key = station%5B'statusKey'%5D%0A%0A        print '%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D'.format(cb_station_id, cb_station_name,cb_location,lat,lon,tot_docks,avb_docks,avb_bikes,last_commu_time,status,is_test_station,status_key)%0A        fh_cb.writelines('%5Cn%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D,%7B%7D'.format(cb_station_id, cb_station_name,cb_location,lat,lon,tot_docks,avb_docks,avb_bikes,last_commu_time,status,is_test_station,status_key))%0A%0A    station_count = len(all_station_info)%0A    print '%5CnNumber of Citi Bike stations ', station_count%0A%0A    break%0A%0A%0A# create DataFrame using Pandas%0A#fh_cb = open(fname, 'r')%0A#df_cb = pd.read_csv(fname)%0A#df_cb.head(20)%0A%0A%0A%0A%0A%0A

Add Citi Bike Station Data