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

added bad sites functionality #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions bing_image_downloader/bing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@


class Bing:
def __init__(self, query, limit, output_dir, adult, timeout, filter='', verbose=True):
def __init__(self, query, limit, output_dir, adult, timeout, filter='', verbose=True,badsites=[]):
self.download_count = 0
self.query = query
self.output_dir = output_dir
self.adult = adult
self.filter = filter
self.verbose = verbose
self.badsites = badsites
self.seen = set()

if self.badsites:
print("Download links will not include: {}".format(*self.badsites),sep=', ')

assert type(limit) == int, "limit must be integer"
self.limit = limit
assert type(timeout) == int, "timeout must be integer"
Expand Down Expand Up @@ -106,7 +110,21 @@ def run(self):
print("[%] Indexed {} Images on Page {}.".format(len(links), self.page_counter + 1))
print("\n===============================================\n")

for link in links:

for link in links:

isbadsite = False

for badsite in self.badsites:
isbadsite = badsite in link
if isbadsite:
if self.verbose:
print("[!] Link included in badsites {}".format(badsite,link))
break

if isbadsite:
continue

if self.download_count < self.limit and link not in self.seen:
self.seen.add(link)
self.download_image(link)
Expand Down
4 changes: 2 additions & 2 deletions bing_image_downloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def download(query, limit=100, output_dir='dataset', adult_filter_off=True,
force_replace=False, timeout=60, filter="", verbose=True):
force_replace=False, timeout=60, filter="", verbose=True,bad_sites=[]):

# engine = 'bing'
if adult_filter_off:
Expand All @@ -34,7 +34,7 @@ def download(query, limit=100, output_dir='dataset', adult_filter_off=True,
sys.exit(1)

print("[%] Downloading Images to {}".format(str(image_dir.absolute())))
bing = Bing(query, limit, image_dir, adult, timeout, filter, verbose)
bing = Bing(query, limit, image_dir, adult, timeout, filter, verbose,bad_sites)
bing.run()


Expand Down