#NEWLINE# def download_data( page_url ) : #NEWLINE# #INDENT# document = urllib2 . urlopen ( ( ROOT + page_url ) ) #NEWLINE# html = document . read ( ) #NEWLINE# soup = Soup ( html ) #NEWLINE# download_string = ( ( '/download/.{9}/(' + '|' . join ( FORMATS ) ) + ')' ) #NEWLINE# download_re = re . compile ( download_string , re . I ) #NEWLINE# downloads = soup . find_all ( href = download_re ) #NEWLINE# if ( len ( downloads ) == 0 ) : #NEWLINE# #INDENT# number = page_url [ ( - 9 ) : ] #NEWLINE# url = 'http://explore.data.gov/api/views/{0}/rows.csv?accessType=DOWNLOAD' . format ( number ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# url = ( ROOT + downloads [ 0 ] . attrs [ 'href' ] ) #NEWLINE# #UNINDENT# return url