def advanced_search(tegs: list): """Search in tegs or teg's parts, in description Take list of tegs for search Return list of images which passed search """ images = db.get_images() if not tegs or tegs[0] == '' or tegs is None: return db.get_images_without_teg() for teg in tegs: temp_images = [] for j in range(len(images)): try: tegs = images[j][2].lower() except AttributeError: tegs = "" try: desc = images[j][3].lower() except AttributeError: desc = "" if teg.lower() in tegs or teg.lower() in desc: temp_images.append(images[j]) images = temp_images return images
def process_comment(self, comment, template=BODY): """Check for matches in a comment and reply""" matches = MAYBE_IMAGE.findall(comment.body) images = [] candidate = None if matches and BotComment.get_by_parent(comment.id): # already processed return None for match in matches: word = unicodedata.normalize('NFD', match[0]).encode( 'ascii', 'ignore').decode('utf8') word = word.lower() word = ONLY_WORDS.sub('', word) candiates = get_images(word, match[1].lower() in ANIM_EXT) if not candiates: fuzzy_word = get_fuzzy_images(word) if fuzzy_word: self._logger.info('Fuzzy %s -> %s', word, fuzzy_word) if len(matches) == 1: comment.body = fuzzy_word + '.' + match[1] return self.process_comment(comment, BODY_FORCE) else: candiates = get_images(fuzzy_word, match[1].lower() in ANIM_EXT) if not candiates: candidate = KeywordCandidate.get_or_create(word) if candidate.ignored: continue candidate.hits = candidate.hits + 1 self._logger.info('Canditate found "%s" on comment %s', candidate.keyword, comment.permalink) continue imageurl = random.choice(candiates) images.append('[%s.%s](%s)' % (word, match[1], imageurl)) if images: body = template.format(images='\n\n'.join(images), username=self.username, comment_id=comment.id) reply = comment.reply(body) self._logger.info('Posted comment: %s -> %s', comment.permalink, reply.id) db.add(BotComment(reply)) if images or candidate: db.commit() return images
def getImages(): requestBody = loads(request.body.read()) token = requestBody['token'] product = requestBody['product'] productID = product['id'] images = [] if productID : images = database.get_images(key_name=productID, bucket="brazaar") # append images in to product json product['images'] = images return product
def get_gallery_info(path): # get info about the specified gallery to check if it exists gallery_info = db.get_gallery_info(path) if not gallery_info: # gallery does not exist response.status = 404 return # get all images in the specified gallery images = db.get_images(path) response.headers['Content-Type'] = 'application/json' return json.dumps({'gallery': gallery_info, 'images': images})
def home(): global email if (request.method == 'POST'): email = request.form['email'] password = request.form['pw'] db.create_connection() authenticate(email, password) for item in db.get_messages(): if (item[1] == email): messages.append( (item[0], item[2], "".join(cc.decode(item[2], 3)))) for item in db.get_images(): if (item[1] == email): images.append((item[0], item[2])) return render_template('home.html', email=email, messages=messages, images=images) else: return render_template('login.html')
def get_galleries(): # get gallery paths and names galleries_info_noimg = db.get_galleries() # get images galleries_info = [] for path, name in galleries_info_noimg: gallery = { 'path': path, 'name': name, } # get images from the current gallery imgs = db.get_images(name) if imgs: gallery['image'] = imgs[0] galleries_info.append(gallery) response.headers['Content-Type'] = 'application/json' return json.dumps({'galleries': galleries_info})
def search(tegs: list): """Take list of tegs for search Return list of images with given tegs """ images = db.get_images() if not tegs or tegs[0] == '' or tegs is None: return images for teg in tegs: temp_images = [] for j in range(len(images)): try: tegs = images[j][2] tegs = tegs.split(', ') except AttributeError: continue except Exception: print('Damned... Exception - def search') continue if teg in tegs: temp_images.append(images[j]) images = temp_images return images
def main_refresh(self): self.refresh_images(db.get_images()) self.refresh_teg() self.root.title("DVP " + "Search ALL")