Skip to content

Commit a1c8789

Browse files
committed
Finalizing fixes
1 parent 0271b36 commit a1c8789

File tree

7 files changed

+26
-16
lines changed

7 files changed

+26
-16
lines changed

Image/Download.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,31 @@
66

77

88
class Download():
9-
path = 'storage/images'
9+
folder = 'storage/'
1010

11-
def __init__(self, take=None):
11+
def __init__(self, take=None, links=None, path="images"):
1212
self.queue = Models.Queue.Image.Image()
1313
self.complete = Models.Complete.Image.Image()
1414
self.limit = take
15+
self.path = self.folder + path
16+
1517
if not os.path.exists(self.path):
1618
os.makedirs(self.path)
1719

20+
if isinstance(links, set):
21+
self.links = links
22+
else:
23+
self.links = self.queue.links
24+
1825
def start(self) -> object:
1926
"""
2027
Start Downloading file
2128
:rtype: object
2229
"""
23-
if isinstance(self.limit, int) and len(self.queue.links) >= self.limit:
24-
links = sorted(self.queue.links)[0:self.limit]
30+
if isinstance(self.limit, int) and len(self.links) >= self.limit:
31+
links = sorted(self.links)[0:self.limit]
2532
else:
26-
links = self.queue.links
33+
links = self.links
2734

2835
for file in links:
2936
try:
@@ -32,7 +39,7 @@ def start(self) -> object:
3239
except Exception as e:
3340
print(str(e))
3441
self.complete.add(file)
35-
self.save()
42+
return self
3643

3744
def save(self) -> object:
3845
"""
70 Bytes
Binary file not shown.

Models/Complete/Image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class Image(Model):
5-
file_path = 'storage/complete/images.txt'
5+
file_path = 'storage/complete/gopostie.txt'
66

77
def __init__(self):
88
Model.__init__(self)
2 Bytes
Binary file not shown.

Models/Queue/Image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class Image(Model):
5-
file_path = 'storage/queue/images.txt'
5+
file_path = 'storage/queue/gopostie.txt'
66

77
def __init__(self):
88
Model.__init__(self)
2 Bytes
Binary file not shown.

test.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
from Crawler.Page import Page
55
from Crawler.Image import Image
66
from Image.Download import Download
7+
import functions
78

89
if __name__ == '__main__':
9-
# page=Page('https://gopostie.com')
10-
# page.save_links()
11-
12-
# img = Image('https://gopostie.com')
13-
# img.save_links()
14-
15-
down = Download()
16-
down.start()
10+
page = Page('https://gopostie.com')
11+
links = page.fetch_links()
12+
for link in sorted(links):
13+
print('Downloading ...' + link)
14+
img = Image(link)
15+
images = img.fetch_links()
16+
down = Download(links=images,path=functions.get_folder_name(link))
17+
down.start()
18+
# down = Download()
19+
# down.start()

0 commit comments

Comments
 (0)