Delete 'unsplash.py'
This commit is contained in:
parent
faa7182847
commit
c346a9a335
55
unsplash.py
55
unsplash.py
|
@ -1,55 +0,0 @@
|
|||
import sys, requests, os
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
choice = input("Download from New Section? (y/n) -> ")
|
||||
if(choice == 'y'):
|
||||
url = 'https://unsplash.com/new'
|
||||
else:
|
||||
url = 'https://unsplash.com'
|
||||
|
||||
os.makedirs('Wallpapers', exist_ok=True)
|
||||
|
||||
n = int(input("How many photos to download? -> "))
|
||||
|
||||
print("Trying to contact Unsplash...")
|
||||
page = requests.get(url)
|
||||
print("Done!")
|
||||
|
||||
print("Finding Images...")
|
||||
soup = BeautifulSoup(page.content, "html.parser")
|
||||
links = soup.find_all('a', href=True)
|
||||
|
||||
pic_links = []
|
||||
|
||||
for link in links:
|
||||
if('photos' in link.get('href')):
|
||||
pic_links.append(link.get('href'))
|
||||
|
||||
numbers_of_links = len(pic_links)
|
||||
sentence = "Found " + str(numbers_of_links) + " Images"
|
||||
print(sentence)
|
||||
|
||||
if(numbers_of_links == 0):
|
||||
print("\nAborting...")
|
||||
sys.exit()
|
||||
|
||||
i = 1
|
||||
|
||||
for link in pic_links:
|
||||
pic = requests.get(link)
|
||||
name = os.path.dirname(link)
|
||||
name = name[30:]
|
||||
if(os.path.isfile('Wallpapers/' + name) == True):
|
||||
print("\nFile '%s' Exists. Skipping..." %(name))
|
||||
continue
|
||||
else:
|
||||
print("\nDownloading '%s'..." %(name))
|
||||
with open(os.path.join('Wallpapers/', name), 'wb') as image:
|
||||
for chunk in pic.iter_content(1000000):
|
||||
image.write(chunk)
|
||||
print("Done!")
|
||||
i = i + 1
|
||||
if(i > n):
|
||||
break
|
||||
|
||||
print("\nTask Done.")
|
Loading…
Reference in New Issue