Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

download #2

Open
ghost opened this issue Sep 16, 2019 · 0 comments
Open

download #2

ghost opened this issue Sep 16, 2019 · 0 comments

Comments

@ghost
Copy link

ghost commented Sep 16, 2019

Downloads resource images with the specified terms

def __resourceDownloader(self, count=300):
for person in self.__persons:
print("--Downloading Resources for '{}'".format(person))
folder = "./tmp/downloaded_images/" + person
# Fetch links from Bing Images and download images
BingImages.download(BingImages(person + " face", count=count, person="portrait").get(), folder)
counter = 0
# Rename the files accordingly
for filename in os.listdir(folder):
filepath = folder + "/" + filename
, file_extension = os.path.splitext(filepath)
# Remove files that are of wrong type or too small
if file_extension.lower() not in [".jpg", ".jpeg"] or os.path.getsize(filepath) < 1024*128: # File not jpeg smaller than 128kb
os.remove(filepath)
continue
tries = 0
# Rename all other files with fitting schema "img_X.jpg"
while(tries < 1000000):
try:
os.rename(filepath, folder + "/" + "image
" + str(counter) + ".jpg")
break
# Catch error that a file may exist already with a certain name
except FileExistsError:
tries += 1
counter += 1
pass
counter += 1

im using this code which i believe you made but is not working for some reason is there any error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants