Skip to content

Commit

Permalink
Merge pull request #1 from wwwpf/master
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
Yang-z authored Dec 24, 2018
2 parents 691cabd + f2b625b commit 7c086c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 8 additions & 5 deletions download.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

@logging_wrap
def download_media(url, dir, file_name):
result = False
s = "\rdownloading %s -> %05.2f%% "
chunk_size = 1024
with closing(requests.get(url, stream=True)) as r:
with requests.get(url, stream=True, timeout=30) as r:
extension = "jpg"
if "content-type" in r.headers:
content_type = r.headers["content-type"]
Expand All @@ -36,7 +37,9 @@ def download_media(url, dir, file_name):
current_len += len(data)
percent = 100 * current_len / total_len
print(s % (url, percent), end="")
print("\n%s is downloaded" % url)
result = True
print("\n%s is downloaded" % url)
return result


@logging_wrap
Expand Down Expand Up @@ -115,7 +118,7 @@ def download(self):

download_dir = temp[1]
id = temp[2]
download_media(url, download_dir, id)
fupdate.write("%s\n" % url)
fupdate.flush()
if download_media(url, download_dir, id):
fupdate.write("%s\n" % url)
fupdate.flush()
print("downloading done")
4 changes: 4 additions & 0 deletions tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def get_json_data_from_response(resp_text):


def purge_file_name(file_name):
temp = file_name
file_name = ""
for c in temp:
file_name += "_" if c.isspace() else c
escape_chars = "/\\:*?\"<>|"
for c in escape_chars:
file_name = file_name.replace(c, "%%%X" % ord(c))
Expand Down

0 comments on commit 7c086c8

Please sign in to comment.