def find_shots(self): """ Using the frame difference calculated before, it finds shot boundaries and saves the end frame no. of each shot in self.shots. """ counter = 0 # a local maxima in FD indicates a potential gradual transition diff_fd = np.diff(self.fd) # iterate! for i in range(2, self.total_frames - 2): # naively checking for local maxima # in diff_fd, x corresponds to x-1 local_max = diff_fd[i + 1] < 0 and diff_fd[i] > 0 # if this FD is above a threshold and a local max, it # corresponds to a gradual transition boundary if self.fd[i] > self.upper_bound and local_max: # add only if shots are 8s apart if not search(self.shots, int(i - self.fps * 8), int(i + self.fps * 8)): self.shots.append(i - self.frame_diff_interval) # check for abrupt transition boundary else: # if a series of FD are above a certain threshold, it # is an abrupt transition if self.fd[i] > self.lower_bound and self.fd[ i - 1] > self.lower_bound: counter += 1 else: counter = 0 if counter >= self.abrupt_trans_cnt: counter = 0 if not search(self.shots, i - self.fps * 8, i + self.fps * 8): self.shots.append(i - self.abrupt_trans_cnt - self.frame_diff_interval) self.total_shots = len(self.shots)
def search(request): pm = helpers.PageManager(request, 'stweb/views/search_results.html') if 'searchstring' in request.GET: searchstring = request.GET['searchstring'] else: pm.setForm(ViewSearchForm(request.POST)) if not pm.form.is_valid(): return pm.render() searchstring = pm.form.cleaned_data['searchstring'] searchstring = searchstring.strip() searchresults = helpers.search(pm.object_store, searchstring) # Go directly to the result for a single match. if searchresults['resultcount'] == 1: if searchresults['singleresult'].class_name == 'device': return pm.redirect('device.display', (searchresults['singleresult'].oid,)) if searchresults['singleresult'].class_name == 'device category': return pm.redirect('device.display', (searchresults['singleresult'].oid,)) if searchresults['singleresult'].class_name == 'ipv4 network': return pm.redirect('network.display', (searchresults['singleresult'].oid,)) pm.render_var['searchresults'] = searchresults return pm.render()
def search(): # ET-5, ET-19 ''' Search for all words that match a particular substring usage: /search?q=<string> or frontend search bar ''' if 'q' not in request.args or request.args['q'] == '': abort(400) query = request.args['q'] if 'page' not in request.args: return redirect(url_for('web.search', q=query, page=1)) page = int(request.args['page']) if page < 1: abort(400) per_page = 20 results = helpers.search(query, page=page, per_page=per_page) return helpers.render_search_template('results.html', query=query, results=results[0], results_length=results[1], page=page, page_count=int(math.ceil(results[1]/per_page)), body_class="search", title='Results for {}'.format(query))
def search(request): pm = helpers.PageManager(request, 'stweb/views/search_results.html') if 'searchstring' in request.GET: searchstring = request.GET['searchstring'] else: pm.setForm(ViewSearchForm(request.POST)) if not pm.form.is_valid(): return pm.render() searchstring = pm.form.cleaned_data['searchstring'] searchstring = searchstring.strip() searchresults = helpers.search(pm.object_store, searchstring) # Go directly to the result for a single match. if searchresults['resultcount'] == 1: if searchresults['singleresult'].class_name == 'device': return pm.redirect('device.display', (searchresults['singleresult'].oid, )) if searchresults['singleresult'].class_name == 'device category': return pm.redirect('device.display', (searchresults['singleresult'].oid, )) if searchresults['singleresult'].class_name == 'ipv4 network': return pm.redirect('network.display', (searchresults['singleresult'].oid, )) pm.render_var['searchresults'] = searchresults return pm.render()
def search(): # ET-5, ET-19 """ Search for all words that match a particular substring usage: /search?q=<string> or frontend search bar """ query = request.args["q"] results = helpers.search(query)[0] response = json.dumps(results) return response
def index(): if request.method == "GET": return render_template("index.html") else: search_string = "?q=%s" % request.form.get('query') food_data = search(api_id, api_key, search_string) session["search_data"] = info_filter(food_data) params = { 'page': 'search', 'title': 'Search results for \'%s\'' % request.form.get('query'), 'button_class': 'search-btn' } return render_template("cards.html", data=session["search_data"], params=params)
def get(self, paths, flat=True): try: output = {} with open(self.filename, 'rb') as f: l = yaml.safe_load(f.read()) for path in paths: if path.strip('/'): output = merge(output, search(l, path)) else: return flatten(l) if flat else l return flatten(output) if flat else output except IOError as e: print(e, file=sys.stderr) if e.errno == 2: print("Please, run init before doing plan!") sys.exit(1) except TypeError as e: if 'object is not iterable' in e.args[0]: return dict() raise
def findRecipe(): ingredients = db.execute( "SELECT ingredient FROM ingredient1 WHERE users_id=:id", id=session["user_id"]) allIngredients = [] for ingredient in ingredients: allIngredients.append(ingredient["ingredient"]) try: food = search(allIngredients) mealImage = food["mealImage"] session["title"] = food["title"] session["recipeId"] = food["id"] return render_template("findRecipe.html", food=food, mealImage=mealImage, title=session["title"]) except (KeyError, TypeError, ValueError, IndexError): flash("Invalid Ingredient") return render_template("fridge.html")
def adv_search(): if request.method == "GET": return render_template("adv_search.html") else: search_string = "?q=%s" % request.form.get('query') if request.form.get('diet'): search_string = search_string + "&diet=%s" % request.form.get('diet') for key, value in request.form.to_dict().items(): if key != 'diet' and key != 'query': search_string = search_string + "&health=%s" % value food_data = search(api_id, api_key, search_string) session["search_data"] = info_filter(food_data) params = { 'page': 'search', 'title': 'Search results for \'%s\'' % request.form.get('query'), 'button_class': 'search-btn' } return render_template("cards.html", data=session["search_data"], params=params)
def main_func(): # Get configurations and load into local variable. config = hs.import_configurations(sys.argv) if not config: sys.exit() # Unpack the configuration variables RUN_MODE = config["RUN_MODE"] RUN_TYPE = config["RUN_TYPE"] TARGET_URL = config["URLS"]["target_url"] KEYWORDS = config["KEYWORDS"]["job_title"] HASHTAGS = config["KEYWORDS"]["hashtags"] FN_SAVED_GUIDS = config["FILES"]["saved_guids"] FN_RECORDS = config["FILES"]["records"] LIMITS = config["LIMITS"] API_URL_GET_USER = config["URLS"]["li_api_get_user_profile"] # Fetch JSON format job posting data. Store current data to guid file. data = hs.get_job_data(TARGET_URL) # Filter out non-IT jobs. it_jobs = hs.filter_data(data, KEYWORDS) # Create KEEP and REMOVE list. keep_remove = hs.compare_and_keep(it_jobs, FN_SAVED_GUIDS) keepers = keep_remove["keep"] # Create a list of GUIDS from which the user can choose from. suggestions = hs.make_suggestions(keepers, FN_RECORDS, LIMITS) # Interface with user. if len(suggestions) == 0: print( "Nothing to post for now. Check back again soon. Exiting program.") sys.exit() else: job_list_json = [] for job in it_jobs: if job["guid"] in suggestions: job_list_json.append(job) if RUN_MODE == "MANUAL": user_selections = selector.present_menu(job_list_json) else: user_selections = hs.apply_config_selections(config, job_list_json) # Make connection with LinkedIn API if user_selections: linkedin_assist_obj = LinkedinAssist( config) # <-- Basically a modified OAuth2 Request Object # Check for existing token try: token_file = open("./data/token") token = json.load(token_file) linkedin_assist_obj.get_access(token=token) print(STR["main_token_present"]) except IOError: print( "[main] Warning: File access error. Reverting to manual authentication." ) # Perform manual authentication if Token isn't present or expired. if not linkedin_assist_obj.session.authorized: if RUN_MODE != "AUTO": linkedin_assist_obj.get_access() if not linkedin_assist_obj.session.authorized: print( "[main] Error: Authentication could not be made. Exiting Program" ) sys.exit() else: print( "[main] Authentication Error: Token problem. Possibly expired." ) sys.exit() # Token is good - save to file for future use. else: try: with open("./data/token", "w") as token_save: token_save.seek(0) json.dump(token, token_save, indent=2) token_save.truncate() except IOError: print("[main] Error saving token to file.") # Set URN urn = linkedin_assist_obj.get_urn(API_URL_GET_USER) try: # POST request to LinkedIn & update records # Load records file (date last posted, total times posted) with open(FN_RECORDS, "r+") as r: records = json.load(r) # For each selection: # 1. Create the base message (from random message bank (templates)) # 2. Add hashtags from hashtagbank # 3. edit_language is a catch all method to fix small language bugs for example using UX abbrv. # (might move this into the english module.) # 4. Create the job request post. # 5. Submit request to POST or print to console. for selection in user_selections["posts"]: job = hs.search( selection.split(":")[1].strip(), job_list_json) msg = hs.create_message(job, messages.MESSAGES) msg = hs.add_hashtags(msg, HASHTAGS) msg = hs.edit_language(msg) post = linkedin_assist_obj.form_post(job, urn, msg) if linkedin_assist_obj.make_posts(post): if ("DEVELOPMENT" or "TEST") in RUN_TYPE: print("DEMO print:") else: print("POSTED text:") hs.update_records(r, records, job, today) print(msg) print("\nSuccess! [{}]\n\n".format(job["title"])) else: print("\nFailed :( [{}]\n\n".format(job["title"])) except IOError: print("[main] Error: Records file could not be accessed.") print(" No posts made to LinkedIn:\n\n{}".format( sys.exc_info())) raise else: print("No shares made to LinkedIn. Exiting Program.")
def search(request): searchstring = None search_attribute = 'name' search_value = str() search_attributes = None search_attributes_list = [] advanced_search = False display_types = [] default_display_types = [ 'devices', 'device categories', 'passwords', 'password categories', 'networks' ] pm = helpers.PageManager(request, 'stweb/views/search_results.html') # Determine if we're using the advanced search form or not. if 'searchAttribute' in request.GET: pm.setForm(ViewAdvancedSearchForm(request.GET)) advanced_search = True else: pm.setForm(ViewSearchForm(request.POST)) if not pm.form.is_valid(): return pm.render() if advanced_search: search_attribute = pm.form.cleaned_data['searchAttribute'].replace( ' ', '_').lower() search_value = pm.form.cleaned_data['searchValue'] search_attributes = pm.form.cleaned_data['attributesList'] display_types = pm.form.cleaned_data['displayTypes'] else: searchstring = pm.form.cleaned_data['searchstring'] display_types = default_display_types if search_value: search_value = search_value.strip().lower() # Restrict number of attribute names we can show in the html table. if search_attributes: for attribute_name in search_attributes.split(',')[:5]: search_attributes_list.append(attribute_name.strip()) if searchstring: searchstring = searchstring.strip().lower() searchresults = helpers.search(pm.object_store, searchstring) else: searchstring = search_value.strip().lower() searchresults = helpers.search(pm.object_store, searchstring, [search_attribute]) # Go directly to the result for a single match. if searchresults['resultcount'] == 1: if searchresults['singleresult'].class_name == 'device': return pm.redirect('device.display', (searchresults['singleresult'].oid, )) if searchresults['singleresult'].class_name == 'device category': return pm.redirect('device.display', (searchresults['singleresult'].oid, )) if searchresults['singleresult'].class_name == 'ipv4 network': return pm.redirect('network.display', (searchresults['singleresult'].oid, )) pm.render_var['searchresults'] = searchresults pm.render_var['searchstring'] = searchstring pm.render_var['search_attribute'] = search_attribute pm.render_var['attributes_list'] = search_attributes_list pm.render_var['display_types'] = display_types pm.render_var['browsable_path'] = [{ 'name': 'Search results', 'path': '/search/' }] return pm.render()
def home(): if "q" in request.args and request.args["q"] != "": filtered = helpers.search(ontology, request.args["search_by"], request.args["q"]) else: filtered = helpers.search(ontology, "label", "Southeast Asia") return render_template("home.html", ontology=filtered)
def site_command(*terms): for url in urls: if url.count("%s") == 1: helpers.search(url, terms) else: helpers.browser(url)
def filter(): if request.method == "GET": # Initialize casting lists co = [] cd = [] ca = [] # Connect to database conn = sqlite3.connect("auditionstats.db") conn.row_factory = sqlite3.Row c = conn.cursor() user_id = (session["user_id"], ) c.execute("SELECT * FROM auditions WHERE user_id=?", user_id) r = c.fetchall() # Populate casting lists, skipping duplicates for i in range(len(r)): if r[i]["co"] not in co and r[i]["co"] != None: co.append(r[i]["co"]) if r[i]["cd"] not in cd and r[i]["cd"] != None: cd.append(r[i]["cd"]) if r[i]["ca"] not in ca and r[i]["ca"] != None: ca.append(r[i]["ca"]) # Sort casting lists alphabetically co = sorted(co) cd = sorted(cd) ca = sorted(ca) # Close database conn.close() return render_template("filter.html", **locals()) # If request method = POST, filter out rows of auditions based on search criteria else: # Connect to database r = connect(session["user_id"]) # Save search criteria in variables year = request.form.get("year") month = request.form.get("month") day = request.form.get("day") title = request.form.get("title") type_t = request.form.get("type") role = request.form.get("role") co = request.form.get("co") cd = request.form.get("cd") ca = request.form.get("ca") # Change these variables from bools to strings (important later) cb = request.form.get("cb") if cb: cb = "Called Back" booked = request.form.get("booked") if booked: booked = "Booked" self_tape = request.form.get("self_tape") if self_tape: self_tape = "Self Tape" # Delete rows of auditions if they don't match search criteria for date if year != "Year...": for i in range(len(r) - 1, -1, -1): if r[i][2][:4] != year: del r[i] if month and month != "Month...": month = int(month) month = f"{month:02d}" for i in range(len(r) - 1, -1, -1): if r[i][2][5:7] != month: del r[i] if day and day != "Day...": day = int(day) day = f"{day:02d}" for i in range(len(r) - 1, -1, -1): if r[i][2][8:] != day: del r[i] # Delete rows that do not contain the criteria. r = search(title, 3, r) r = search(type_t, 4, r) r = search(role, 5, r) r = search(cd, 6, r) r = search(ca, 7, r) r = search(co, 8, r) r = search(self_tape, 9, r) r = search(cb, 10, r) r = search(booked, 11, r) # Initialize empty lists to show results date = [] title = [] type_t = [] role = [] cd = [] ca = [] co = [] self_tape = [] cb = [] booked = [] notes = [] # Populate lists for i in range(len(r)): date.append(r[i][2]) title.append(r[i][3]) type_t.append(r[i][4]) role.append(r[i][5]) cd.append(r[i][6]) ca.append(r[i][7]) co.append(r[i][8]) self_tape.append(r[i][9]) cb.append(r[i][10]) booked.append(r[i][11]) notes.append(r[i][12]) return render_template("filtered.html", **locals())
def search(): q = flask.request.args.get("q") return helpers.search(q)
def search(request): searchstring = None search_attribute = 'name' search_value = str() search_attributes = None search_attributes_list = [] advanced_search = False display_types = [] default_display_types = [ 'devices', 'device categories', 'passwords', 'password categories', 'networks' ] pm = helpers.PageManager(request, 'stweb/views/search_results.html') # Determine if we're using the advanced search form or not. if 'searchAttribute' in request.GET: pm.setForm(ViewAdvancedSearchForm(request.GET)) advanced_search = True else: pm.setForm(ViewSearchForm(request.POST)) if not pm.form.is_valid(): return pm.render() if advanced_search: search_attribute = pm.form.cleaned_data['searchAttribute'].replace(' ', '_').lower() search_value = pm.form.cleaned_data['searchValue'] search_attributes = pm.form.cleaned_data['attributesList'] display_types = pm.form.cleaned_data['displayTypes'] else: searchstring = pm.form.cleaned_data['searchstring'] display_types = default_display_types if search_value: search_value = search_value.strip().lower() # Restrict number of attribute names we can show in the html table. if search_attributes: for attribute_name in search_attributes.split(',')[:5]: search_attributes_list.append( attribute_name.strip() ) if searchstring: searchstring = searchstring.strip().lower() searchresults = helpers.search(pm.object_store, searchstring) else: searchstring = search_value.strip().lower() searchresults = helpers.search( pm.object_store, searchstring, [search_attribute] ) # Go directly to the result for a single match. if searchresults['resultcount'] == 1: if searchresults['singleresult'].class_name == 'device': return pm.redirect('device.display', (searchresults['singleresult'].oid,)) if searchresults['singleresult'].class_name == 'device category': return pm.redirect('device.display', (searchresults['singleresult'].oid,)) if searchresults['singleresult'].class_name == 'ipv4 network': return pm.redirect('network.display', (searchresults['singleresult'].oid,)) pm.render_var['searchresults'] = searchresults pm.render_var['searchstring'] = searchstring pm.render_var['search_attribute'] = search_attribute pm.render_var['attributes_list'] = search_attributes_list pm.render_var['display_types'] = display_types pm.render_var['browsable_path'] = [{ 'name': 'Search results', 'path': '/search/' }] return pm.render()
def test_search(): assert search(world, current_player_id, 2, 2) == -1 assert search(world, current_player_id, 0, 2) == (1, 2)