
import os
import pandas as pd
from urllib.request import urlretrieve

FREMONT_URL = 'https://data.seattle.gov/api/views/65db-xm6k/rows.csv?accessType=DOWNLOAD'

def get_data(filename='Fremont.csv', url=FREMONT_URL, force_download=False):

	"""Download and cache the fremont data

	Parameters
	----------
	filename : string (optional)
		location to save the data 
	url : string (optional)
		web location of the data
	force_download : bool (optional)
		if True, force redownload of data

	Returns
	-------
	data : pandas.DataFrame
		The Fremont Bridge data	
	"""

	if not force_download or not os.path.exist(filename):
		urlretrieve(url, filename)
		
	data = pd.read_csv(filename, index_col='Date', parse_dates=True)
	data.columns= ['West', 'East']
	data['Total'] = data['West'] + data['East']
	return data



import os
import pandas as pd
from urllib.request import urlretrieve

FREMONT_URL = 'https://data.seattle.gov/api/views/65db-xm6k/rows.csv?accessType=DOWNLOAD'

def get_data(filename='Fremont.csv', url=FREMONT_URL, force_download=False):

	"""Download and cache the fremont data

	Parameters
	----------
	filename : string (optional)
		location to save the data 
	url : string (optional)
		web location of the data
	force_download : bool (optional)
		if True, force redownload of data

	Returns
	-------
	data : pandas.DataFrame
		The Fremont Bridge data	
	"""

	if not force_download or not os.path.exist(filename):
		urlretrieve(url, filename)
	data = pd.read_csv('Fremont.csv', index_col='Date')

	try:
	    data.index = pd.to_datetime(data.index, format='%m/%d/%Y %H:%M:%S %p')
	except TypeError:
	    data.index = pd.to_datetime(data.index)
		
	data.columns= ['West', 'East']
	data['Total'] = data['West'] + data['East']
	return data


Refactor data download