-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcore.py
More file actions
28 lines (26 loc) · 795 Bytes
/
core.py
File metadata and controls
28 lines (26 loc) · 795 Bytes
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
# -*- coding: utf-8 -*-
#!/usr/local/bin/python3
from urllib.request import urlopen
import re
import os
import sys
def download_pics(author,title,link):
save_folder = os.path.join(os.getcwd(),"pics",author,title)
file_name = re.findall("/(\d+.\w+$)",link)[0]
try:
os.makedirs(save_folder);
except:
pass;
if os.path.isfile(os.path.join(save_folder,file_name)):
print("Already downloaded");
else:
try:
res = urlopen(link);
image_data = res.read()
image = open(os.path.join(save_folder,file_name),'wb');
image.write(image_data);
image.close();
except:
print("Error downloading:{} {} {}".format(link,author,title));
if __name__ == "__main__":
print('this')