Skip to content

Commit 888bd26

Browse files
committed
Comic number added to comic name
This is with the aim of placing the comics in good order so as to enable for easier viewing when one has downloaded a lot of the comics Signed-off-by: Victor Otieno Omondi <vickz84259@gmail.com>
1 parent 312c026 commit 888bd26

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

XKCD/web.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_image_url(webpage):
3131
return None
3232

3333

34-
def download_image(url, path):
34+
def download_image(url, path, number):
3535
""" This function downloads and saves the image specified
3636
by the given url.
3737
@@ -41,7 +41,8 @@ def download_image(url, path):
4141
print 'Downloading image {0}...'.format(os.path.basename(url))
4242
res = get_resource(url)
4343

44-
with open(os.path.join(path, os.path.basename(url)), 'wb') as imageFile:
44+
with open(os.path.join(path, number, os.path.basename(url)), 'wb') \
45+
as imageFile:
4546
for chunk in res.iter_content(100000):
4647
imageFile.write(chunk)
4748

scripts/download_xkcd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# download_xkcd.py - Downloads comics from xkcd.com.
44

55
__author__ = 'Victor Otieno Omondi'
6-
__version__ = '2.1.1-alpha'
6+
__version__ = '2.2.1'
77

88
# Standard library modules
99
import logging
@@ -98,8 +98,8 @@ def download_comic(path, start=1, end=0):
9898
start = req.json()['num']
9999
end = start + 1
100100

101-
for i in range(start, end):
102-
url_queue.put('http://xkcd.com/{}/info.0.json'.format(i))
101+
for number in range(start, end):
102+
url_queue.put((number, 'http://xkcd.com/{}/info.0.json'.format(i)))
103103

104104
time.sleep(5)
105105

scripts/workers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def __init__(self, web_queue, image_queue):
2929
def run(self):
3030
while True:
3131
# fetch webpage url from queue
32-
url = self.web_queue.get()
32+
comic_number, url = self.web_queue.get()
3333

3434
# fetch image url from webpage
3535
image_url = xkcd.get_image_url(url)
3636

3737
if image_url is not None:
3838
# place url in download queue
39-
self.image_queue.put(image_url)
39+
self.image_queue.put((comic_number, image_url))
4040

4141
self.web_queue.task_done()
4242

@@ -60,9 +60,9 @@ def __init__(self, path, image_queue):
6060
def run(self):
6161
while True:
6262
# fetch image url from queue
63-
url = self.image_queue.get()
63+
comic_number, url = self.image_queue.get()
6464

6565
# download the image
66-
xkcd.download_image(url, self.path)
66+
xkcd.download_image(url, self.path, comic_number)
6767

6868
self.image_queue.task_done()

0 commit comments

Comments
 (0)