You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							55 lines
						
					
					
						
							1.7 KiB
						
					
					
				
			
		
		
		
			
			
			
		
		
	
	
							55 lines
						
					
					
						
							1.7 KiB
						
					
					
				
								# -*- coding: utf-8 -*-
							 | 
						|
								##############################################################################
							 | 
						|
								#
							 | 
						|
								#    Cybrosys Technologies Pvt. Ltd.
							 | 
						|
								#    Copyright (C) 2023-TODAY Cybrosys Technologies(<http://www.cybrosys.com>).
							 | 
						|
								#    Author: Rahul CK(<https://www.cybrosys.com>)
							 | 
						|
								#    you can modify it under the terms of the GNU LESSER
							 | 
						|
								#    GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
							 | 
						|
								
							 | 
						|
								#    This program is distributed in the hope that it will be useful,
							 | 
						|
								#    but WITHOUT ANY WARRANTY; without even the implied warranty of
							 | 
						|
								#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
							 | 
						|
								#    GNU LESSER GENERAL PUBLIC LICENSE (AGPL v3) for more details.
							 | 
						|
								#
							 | 
						|
								#    You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
							 | 
						|
								#    GENERAL PUBLIC LICENSE (AGPL v3) along with this program.
							 | 
						|
								#    If not, see <http://www.gnu.org/licenses/>.
							 | 
						|
								#
							 | 
						|
								##############################################################################
							 | 
						|
								import sys
							 | 
						|
								import shutil
							 | 
						|
								from pathlib import Path
							 | 
						|
								
							 | 
						|
								try:
							 | 
						|
								    from bing import Bing
							 | 
						|
								except ImportError:
							 | 
						|
								    from .bing import Bing
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								def download(query, limit=100, output_dir='dataset', adult_filter_off=True,
							 | 
						|
								             force_replace=False, timeout=60, filter="", verbose=True):
							 | 
						|
								    if adult_filter_off:
							 | 
						|
								        adult = 'off'
							 | 
						|
								    else:
							 | 
						|
								        adult = 'on'
							 | 
						|
								
							 | 
						|
								    image_dir = Path(output_dir).joinpath(query).absolute()
							 | 
						|
								
							 | 
						|
								    if force_replace:
							 | 
						|
								        if Path.isdir(image_dir):
							 | 
						|
								            shutil.rmtree(image_dir)
							 | 
						|
								
							 | 
						|
								    try:
							 | 
						|
								        if not Path.is_dir(image_dir):
							 | 
						|
								            Path.mkdir(image_dir, parents=True)
							 | 
						|
								
							 | 
						|
								    except Exception as e:
							 | 
						|
								        sys.exit(1)
							 | 
						|
								
							 | 
						|
								    bing = Bing(query, limit, image_dir, adult, timeout, filter, verbose)
							 | 
						|
								    return bing.run()
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								if __name__ == '__main__':
							 | 
						|
								    download('dog', output_dir="..\\Users\\cat", limit=10, timeout=1)
							 | 
						|
								
							 |