def searchImages(): if request.method == 'POST': print("entered post") keyWord = request.form['keyword'] # assigning the value of the input keyword to the variable keyword else: print("did not enter post") print('printing = ' + keyWord) scraper_object = ImageScrapper() # instantiating the class list_of_jpg_files = scraper_object.list_only_jpg_files('static') # obtaining the list of image files from the static folder scraper_object.delete_existing_image(list_of_jpg_files) # deleting the old image files stored from the previous search # splitting and combining the keyword for a string containing multiple words image_name = keyWord.split() image_name = '+'.join(image_name) # adding the header metadata header = { 'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"} service = ImageScrapperService # instantiating the object of class ImageScrapperService # (imageURLList, header, keyWord, fileLoc) masterListOfImages = service.downloadImages(keyWord, header) # getting the master list from keyword imageList = masterListOfImages[0] # extracting the list of images from the master list imageTypeList = masterListOfImages[1] # extracting the list of type of images from the masterlist response = "We have downloaded ", len(imageList), "images of " + image_name + " for you" return show_images() # redirect the control to the show images method
def show_images(): scraper_object=ImageScrapper() #Instantiating the object of class ImageScrapper list_of_jpg_files=scraper_object.list_only_jpg_files('static') # obtaining the list of image files from the static folder print(list_of_jpg_files) try: if(len(list_of_jpg_files)>0): # if there are images present, show them on a wen UI return render_template('showImage.html',user_images = list_of_jpg_files) else: return "Please try with a different string" # show this error message if no images are present in the static folder except Exception as e: print('no Images found ', e) return "Please try with a different string"