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