#NEWLINE# def getCSVFromURL( url , workdir , filename , message = '' ) : #NEWLINE# #INDENT# if ( not os . access ( workdir , os . W_OK ) ) : #NEWLINE# #INDENT# print ( ( ( workdir + ' is not a writeable scratch directory; ' ) + message ) ) #NEWLINE# sys . exit ( ) #NEWLINE# #UNINDENT# sys . path . append ( 'requests' ) #NEWLINE# import requests #NEWLINE# response = requests . get ( ( url + '&output=csv' ) ) #NEWLINE# assert ( response . status_code == 200 ) , 'Wrong status code' #NEWLINE# csvFile = ( ( workdir + '/' ) + filename ) #NEWLINE# with open ( csvFile , 'w' ) as f : #NEWLINE# #INDENT# print ( response . content , file = f ) #NEWLINE# #UNINDENT# print ( 'retrieved CSV file from URL' ) #NEWLINE# return csvFile