티스토리 뷰

프로그래밍

[PYTHON] File IO, Image Download

ReturnToHome 2016. 12. 24. 21:27

image_list.txt :
file_name_1
file_name_2
file_name_3

 

 

image url : 
http://www.test.com/download/image/file_name_1.jpg
http://www.test.com/download/image/file_name_2.jpg
http://www.test.com/download/image/file_name_3.jpg

 

 


def getImageList():
 image_list_files = open('c:/image_list.txt', 'r')
 total_lines = image_list_files.readlines()
 
 for image in total_lines:
  if image != '':
   # 엔터가 붙어있기에 치환해준다.
   image_name = image.replace("\n", "")
   getImageDownload(image_name)
 
 image_list_files.close()

def getImageDownload(image_name):
 
 # 다운받을 로컬 디렉토리
 save_file_path = "%s%s" % ("c:/image_download/", image_name + ".jpg")
 save_local_directory = file(file_path, "wb")
 
 # 파일 다운로드
 image_file = urllib.urlopen("http://www.test.com/download/image/" + image_name +".jpg")
 while True:
  buf = image_file.read(100000000)
  if len(buf) == 0:
   break
  save_local_directory.write(buf)
 
 save_local_directory.close()
 image_file.close()

 

# call
getImageList()

'프로그래밍' 카테고리의 다른 글

[ETC] Singleton Pattern  (0) 2016.12.24
[ETC] Cron Tab  (0) 2016.12.24
[JAVASCRIPT] 유니코드 -> 한글, 한글 -> 유니코드 변환  (0) 2016.12.24
[JAVASCRIPT] MAP 사용  (0) 2016.12.24
[JAVASCRIPT] 클립보드에 복사하기  (0) 2016.12.24
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함