def search_team(search_term): teams = [] for team_pickle in db.search_teams(search_term): team_json = jsonpickle.decode(team_pickle[0], keys=True, classes=team) try: if team_json.pitcher is not None: if len(team_json.rotation ) == 0: #detects old-format teams, adds pitcher team_json.rotation.append(team_json.pitcher) team_json.pitcher = None update_team(team_json) for player in team_json.rotation + team_json.lineup: if player.name == "Tim Locastro": player.randomize_stars() if not hasattr(team_json, "archetypes"): team_json.archetypes = {} except AttributeError: team_json.rotation = [] team_json.rotation.append(team_json.pitcher) team_json.pitcher = None update_team(team_json) except: return None teams.append(team_json) return teams
def search_team(search_term): teams = [] for team_pickle in db.search_teams(search_term): team_object = jsonpickle.decode(team_pickle[0], keys=True, classes=(team, games.team)) try: team_json = get_team(team_object.name) except: return None teams.append(team_json) return teams
def search_teams(): query = request.args.get('query') page_len = int(request.args.get('page_len')) page_num = int(request.args.get('page_num')) if query is None: abort(400, "A query term is required") result = db.search_teams(query) if page_len is not None: #pagination should probably be done in the sqlite query but this will do for now if page_num is None: abort(400, "A page_len argument must be accompanied by a page_num argument") result = result[page_num*page_len : (page_num + 1)*page_len] return jsonify([json.loads(x[0])['name'] for x in result]) #currently all we need is the name but that can change
def search_team(search_term): teams = [] for team_pickle in db.search_teams(search_term): team_json = jsonpickle.decode(team_pickle[0], keys=True, classes=team) try: if team_json.pitcher is not None: if len(team_json.rotation) == 0: #detects old-format teams, adds pitcher team_json.rotation.append(team_json.pitcher) team_json.pitcher = None update_team(team_json) except AttributeError: team_json.rotation = [] team_json.rotation.append(team_json.pitcher) team_json.pitcher = None update_team(team_json) except: return None teams.append(team_json) return teams
def search_team(search_term): teams = [] for team_pickle in db.search_teams(search_term): this_team = jsonpickle.decode(team_pickle[0], keys=True, classes=team) teams.append(this_team) return teams