def enter_UDL_tournaments(t_list): for name, start_date, num_prelims in t_list: try: tourny = Tournament.objects.get(tournament_name = name) except: end_date = str(int(start_date) + 3) tourny = Tournament(tournament_name=name, start_date=start_date, end_date=end_date, prelims = int(num_prelims), association = "UDL") tourny.save()
def create_tournament(cls, meta): name = meta['name'][0] bid_round = int(meta['bid'][0]) prelims = int(meta['prelims'][0]) breaks_to = int(meta['break'][0]) curr_rounds = int(meta['curr_rounds'][0]) tourn = Tournament(tournament_name=name, bid_round=bid_round, prelims=prelims, breaks_to=breaks_to, curr_rounds=curr_rounds) tourn.save() # makes tweet make_tweet(name)
def create_tournament(): data = request.get_json() or {} current_user = get_jwt_identity() user = User.query.filter_by(username=current_user).first() #print(user.id) #return jsonify({'data': user}) if not user: return jsonify({'error': 'Invalid creditentials'}), 401 if 'bracket' not in data: return jsonify({'error': 'Something went wrong.'}), 400 if 'tournamentName' not in data: return jsonify({'error': 'Must include a name.'}), 400 if 'round' not in data: return jsonify({'error': 'Must include a round.'}), 400 tournament = Tournament(tournament_title=data['tournamentName']) title = 'Round ' + str(data['round']) tournament.user_id = user.id # #add players players = [] for p in data['bracket']: players.append(p['playerOne']) players.append(p['playerTwo']) tournament.players = (TournamentPlayers(player_name=person) for person in players) #tournament.matches = [Matches(round=1, player_one=p['playerOne'], player_two=p['playerTwo'])] for p in data['bracket']: match = [ Matches(round=1, title=title, player_one=p['playerOne'], player_two=p['playerTwo']) ] tournament.matches.extend(match) #matches.append(tournament) #tournament.players = (TournamentPlayers(player_name=person['playerOne'])for person in players) #tournament.matches = (Matches(round=data['round'])) #round = Matches(round=data['round']) #round=data['round'] #tournament.matches.round = round #playersList = players.values() db.session.add(tournament) db.session.commit() return jsonify({'data': tournament.to_dict()}), 200
for row in r: p = State(created=timezone.now(), modified=timezone.now(), uid=uuid4(), name=row['name'], abbreviation=row['abbreviation'], population=int(row['population_2017'].replace(',', '')), slug=slugify(row['name']),) p.save() with open('./populate/tournaments.csv') as c: r = DictReader(c) for row in r: p = Tournament(created=timezone.now(), modified=timezone.now(), uid=uuid4(), name=row['name'], slug=slugify(row['name']), number_of_teams=int(row['number_of_teams']),) p.save() with open('./populate/cities.csv') as c: r = DictReader(c) state = State.states.get(name__iexact='California') for row in r: p = City(created=timezone.now(), modified=timezone.now(), uid=uuid4(), name=row['name'], state=State.states.get(name__iexact=row['name_state']), slug=slugify(row['name']+'_'+row['name_state']),) p.save()