Merge pull request #6 from WilliamBriot/master

Created Dockerfile
This commit is contained in:
Saurabh Bhan
2017-09-01 21:52:43 +05:30
committed by GitHub
2 changed files with 39 additions and 21 deletions

13
Dockerfile Normal file
View File

@@ -0,0 +1,13 @@
FROM python:3
RUN mkdir -p /Wallhaven-dl/Wallhaven
WORKDIR /Wallhaven-dl
COPY requirments.txt ./
RUN pip install --no-cache-dir -r requirments.txt
COPY . .
VOLUME /Wallhaven-dl/Wallhaven
CMD [ "python", "./wallhaven-dl.py" ]

View File

@@ -30,12 +30,12 @@ def category():
print('''****************************************************************
Category Codes
all - Every wallpaper.
all - Every wallpaper.
general - For 'general' wallpapers only.
anime - For 'Anime' Wallpapers only.
people - For 'people' wallapapers only.
ga - For 'General' and 'Anime' wallapapers only.
gp - For 'General' and 'People' wallpapers only.
anime - For 'Anime' Wallpapers only.
people - For 'people' wallapapers only.
ga - For 'General' and 'Anime' wallapapers only.
gp - For 'General' and 'People' wallpapers only.
****************************************************************
''')
ccode = input('Enter Category: ')
@@ -62,13 +62,13 @@ def category():
****************************************************************
Purity Codes
sfw - For 'Safe For Work'
sfw - For 'Safe For Work'
sketchy - For 'Sketchy'
nsfw - For 'Not Safe For Work'
ws - For 'SFW' and 'Sketchy'
wn - for 'SFW' and 'NSFW'
sn - For 'Sketchy' and 'NSFW'
all - For 'SFW', 'Sketchy' and 'NSFW'
nsfw - For 'Not Safe For Work'
ws - For 'SFW' and 'Sketchy'
wn - For 'SFW' and 'NSFW'
sn - For 'Sketchy' and 'NSFW'
all - For 'SFW', 'Sketchy' and 'NSFW'
****************************************************************
''')
pcode = input('Enter Purity: ')
@@ -118,8 +118,9 @@ def main():
pgid = int(input('How Many pages you want to Download: '))
print('Number of Wallpapers to Download: ' + str(24 * pgid))
for i in range(1, pgid + 1):
url = BASEURL + str(i)
for j in range(1, pgid + 1):
totalImage = str(24 * pgid)
url = BASEURL + str(j)
urlreq = requests.get(url, cookies=cookies)
soup = bs4.BeautifulSoup(urlreq.text, 'lxml')
soupid = soup.findAll('a', {'class': 'preview'})
@@ -127,18 +128,22 @@ def main():
imgid = res.findall(str(soupid))
imgext = ['jpg', 'png', 'bmp']
for i in range(len(imgid)):
currentImage = (((j - 1) * 24) + (i + 1))
url = 'http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-%s.' % imgid[
i]
for ext in imgext:
iurl = url + ext
imgreq = requests.get(iurl, cookies=cookies)
if imgreq.status_code == 200:
print('Downloading: ' + iurl)
with open(os.path.join('Wallhaven', os.path.basename(iurl)), 'ab') as imageFile:
for chunk in tqdm.tqdm(imgreq.iter_content(1024), total=(int(imgreq.headers['content-length']) / 1024), unit='KB'):
time.sleep(0.01)
imageFile.write(chunk)
break
osPath = os.path.join('Wallhaven', os.path.basename(iurl))
if not os.path.exists(osPath):
imgreq = requests.get(iurl, cookies=cookies)
if imgreq.status_code == 200:
print("Downloading : %s - %s / %s" % ((os.path.basename(iurl)), currentImage , totalImage))
with open(osPath, 'ab') as imageFile:
for chunk in imgreq.iter_content(1024):
imageFile.write(chunk)
break
else:
print("%s already exist - %s / %s" % os.path.basename(iurl), currentImage , totalImage)
if __name__ == '__main__':
main()