__JMY__
MY Devblog
__JMY__
전체 방문자
오늘
어제
  • 분류 전체보기 (52)
    • Dev (52)
      • Algorithm (6)
      • Linux (12)
      • Network (7)
      • Container (2)
      • Python (14)
      • Frontend (2)
      • Etc (9)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • Sorting
  • react
  • frontend
  • tcpdump
  • hash
  • SCP
  • algorithm
  • springboot
  • certificate
  • flexbox
  • network
  • Python
  • wget
  • Ingress
  • Kubernetes
  • Docker
  • Tuple
  • Linux
  • hikaricp
  • flask

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
__JMY__

MY Devblog

Dev/Python

[python] wget 사용하는 방법

2019. 8. 12. 21:57

Python wget 사용법

Python에서 wget을 사용하는 방법입니다.

1) wget 라이브러리 설치

먼저 wget을 사용하기 위해 python wget 라이브러리를 설치합니다.

pip install wget

2) wget으로 다운로드

wget를 import하고 wget.download를 사용하여 다운로드 받을 수 있습니다.

import wget

url = "https://github.com/minyong-jeong/minyong-jeong.github.io/raw/master/images/ryan.jpg"
wget.download(url)

3) bar 디자인 변경 및 다운로드 위치 변경

bar_custom 함수를 만들어 wget.download의 bar변수에 할당하면 wget의 bar 디자인을 변경할 수 있습니다.

또한, wget.download에 out 값을 넣어주면 다운로드 받는 위치를 변경할 수 있습니다.

import wget
import math

def bar_custom(current, total, width=80):
    width=30
    avail_dots = width-2
    shaded_dots = int(math.floor(float(current) / total * avail_dots))
    percent_bar = '[' + '■'*shaded_dots + ' '*(avail_dots-shaded_dots) + ']'
    progress = "%d%% %s [%d / %d]" % (current / total * 100, percent_bar, current, total)
    return progress

def download(url, out_path="."):
    wget.download(url, out=out_path, bar=bar_custom)

if __name__ == "__main__":
    url = "https://github.com/minyong-jeong/minyong-jeong.github.io/raw/master/images/ryan.jpg"
    download(url)

bar_custom 적용하면 bar 디자인이 변경되는 것을 확인할 수 있습니다.

[기존 디자인]
100% [..............................................................................] 59524 / 59524

[변경된 디자인]
100% [■■■■■■■■■■■■■■■■■■■■■■■■■■■■] [59524 / 59524]
반응형

'Dev > Python' 카테고리의 다른 글

[python] scp를 이용한 파일전송  (1) 2019.11.27
[python] file의 md5 checksum 구하는 방법  (0) 2019.08.13
Python 자료형 - 6. 집합 (Set)  (0) 2019.06.30
Python 자료형 - 5. 딕셔너리 (Dictionary)  (0) 2019.06.30
Python 자료형 - 4. 튜플 (Tuple)  (0) 2019.06.30
    'Dev/Python' 카테고리의 다른 글
    • [python] scp를 이용한 파일전송
    • [python] file의 md5 checksum 구하는 방법
    • Python 자료형 - 6. 집합 (Set)
    • Python 자료형 - 5. 딕셔너리 (Dictionary)
    __JMY__
    __JMY__
    공부내용 정리 블로그

    티스토리툴바