song/commands/FileDownload.py
def file_download_using_requests(self,url):
		'''It will download file specified by url using requests module'''
		file_name=url.split('/')[-1]

		if os.path.exists(os.path.join(os.getcwd(),file_name)):
			print 'File already exists'
			return
		#print 'Downloading file %s '%file_name
		#print 'Downloading from %s'%url

		

		try:
			r=requests.get(url,stream=True,timeout=200)
		except requests.exceptions.SSLError:
			try:
				response=requests.get(url,stream=True,verify=False,timeout=200)
			except requests.exceptions.RequestException as e:
				print e
				quit()		
		except requests.exceptions.RequestException as e:
				print e
				quit()	
		chunk_size = 1024
		total_size = int(r.headers['Content-Length'])
		total_chunks = total_size/chunk_size

		file_iterable = r.iter_content(chunk_size = chunk_size)
		tqdm_iter = tqdm(iterable = file_iterable,total = total_chunks,unit = 'KB',
			leave = False
			)		
		with open(file_name,'wb') as f:
			for data in tqdm_iter:
				f.write(data)

				
		#total_size=float(r.headers['Content-Length'])/(1024*1024)
		'''print 'Total size of file to be downloaded %.2f MB '%total_size
		total_downloaded_size=0.0
		with open(file_name,'wb') as f:
			for chunk in r.iter_content(chunk_size=1*1024*1024):
				if chunk:
					size_of_chunk=float(len(chunk))/(1024*1024)
					total_downloaded_size+=size_of_chunk
					print '{0:.0%} Downloaded'.format(total_downloaded_size/total_size)
					f.write(chunk)'''

		print 'Downloaded file %s '%file_name
def file_download_using_requests(self,url):
		'''It will download file specified by url using requests module'''
		file_name=url.split('/')[-1]

		if os.path.exists(os.path.join(os.getcwd(),file_name)):
			print 'File already exists'
			return
		#print 'Downloading file %s '%file_name
		#print 'Downloading from %s'%url

		

		try:
			r=requests.get(url,stream=True,timeout=200)
		except requests.exceptions.SSLError:
			try:
				response=requests.get(url,stream=True,verify=False,timeout=200)
			except requests.exceptions.RequestException as e:
				print e
				quit()		
		except requests.exceptions.RequestException as e:
				print e
				quit()	
		chunk_size = 1024
		total_size = int(r.headers['Content-Length'])
		total_chunks = total_size/chunk_size

		file_iterable = r.iter_content(chunk_size = chunk_size)
		tqdm_iter = tqdm(iterable = file_iterable,total = total_chunks,unit = 'KB',
			leave = False
			)		
		with open(file_name,'wb') as f:
			for data in tqdm_iter:
				f.write(data)

				
		#total_size=float(r.headers['Content-Length'])/(1024*1024)
		'''print 'Total size of file to be downloaded %.2f MB '%total_size
		total_downloaded_size=0.0
		with open(file_name,'wb') as f:
			for chunk in r.iter_content(chunk_size=1*1024*1024):
				if chunk:
					size_of_chunk=float(len(chunk))/(1024*1024)
					total_downloaded_size+=size_of_chunk
					print '{0:.0%} Downloaded'.format(total_downloaded_size/total_size)
					f.write(chunk)'''

		print 'Downloaded file %s '%file_name
def file_download_using_requests ( self , url ) : file_name = url . split ( '/' ) [ - 1 ] if os . path . exists ( os . path . join ( os . getcwd ( ) , file_name ) ) : print 'File already exists' return #print 'Downloading file %s '%file_name #print 'Downloading from %s'%url try : r = requests . get ( url , stream = True , timeout = 200 ) except requests . exceptions . SSLError : try : response = requests . get ( url , stream = True , verify = False , timeout = 200 ) except requests . exceptions . RequestException as e : print e quit ( ) except requests . exceptions . RequestException as e : print e quit ( ) chunk_size = 1024 total_size = int ( r . headers [ 'Content-Length' ] ) total_chunks = total_size / chunk_size file_iterable = r . iter_content ( chunk_size = chunk_size ) tqdm_iter = tqdm ( iterable = file_iterable , total = total_chunks , unit = 'KB' , leave = False ) with open ( file_name , 'wb' ) as f : for data in tqdm_iter : f . write ( data ) #total_size=float(r.headers['Content-Length'])/(1024*1024) '''print 'Total size of file to be downloaded %.2f MB '%total_size
		total_downloaded_size=0.0
		with open(file_name,'wb') as f:
			for chunk in r.iter_content(chunk_size=1*1024*1024):
				if chunk:
					size_of_chunk=float(len(chunk))/(1024*1024)
					total_downloaded_size+=size_of_chunk
					print '{0:.0%} Downloaded'.format(total_downloaded_size/total_size)
					f.write(chunk)''' print 'Downloaded file %s ' % file_name
It will download file specified by url using requests module
It will download file specified by url using requests module