def edit_team(request): team = request.GET.get('teamName', '') country = request.GET.get('country', '') rank = request.GET.get('rank', 0) region = request.GET.get('region', '') wins = request.GET.get('wins', 0) losses = request.GET.get('losses', 0) draws = request.GET.get('draws', 0) coach_name = request.GET.get('coachName', '') coach_gamertag = request.GET.get('coachGamertag', '') best_map = request.GET.get('bestMap', '') worst_map = request.GET.get('worstMap', '') b_map = Maps.objects.get(map_name=best_map) w_map = Maps.objects.get(map_name=worst_map) new_t = Teams(team_name=team, country_of_origin=country, rank=rank, region=region, wins=wins, losses=losses, draws=draws, coach_name=coach_name, coach_gamertag=coach_gamertag, best_map=b_map, worst_map=w_map) new_t.save() context = {"success": True} data = simplejson.dumps(context) return HttpResponse(data, content_type='application/json')
def save_opponent(request): if request.method == "POST": teamname = request.POST['teamname'] teamlevel = request.POST['teamlevel'] wrestler_id = request.POST['wrestler_id'] try: t = Teams.objects.get(name=teamname) except: t = Teams.objects.filter(name=teamname) if len(t) > 1: t = t[0] elif len(t) == 1: t = t[0] else: t = Teams(name=teamname) t.save() if not request.POST['wrestler_dropdown'] == "none_selected": wrestler = request.POST['wrestler_dropdown'] o = Opponents.objects.get(pk=wrestler) else: wrestler = request.POST['wrestler'] o = Opponents() o.name = wrestler o.team = t o.teamlevel = teamlevel o.save() w = Wrestlers.objects.get(pk=wrestler_id) w.current_opponent = o w.save() return HttpResponseRedirect('/teamview/') return HttpResponseRedirect('/teamview/')
def new_team(sport_id): if 'username' not in login_session: return redirect('/login') sport = session.query(Sports).filter_by(id=sport_id).one() if sport.user_id != login_session['user_id']: flash('You are not authorized to add a team to {}'.format(sport.name), 'flash-error') return redirect(url_for('show_sports_teams', sport_id=sport_id)) if request.method == 'POST': new_team = Teams(name=request.form['name'] or "New Team", league=request.form['league'], wins=request.form['wins'] or 0, losses=request.form['losses'] or 0, logo=logo_picker(request), created_date=datetime.datetime.now(), sport_id=sport_id, user_id=login_session['user_id']) session.add(new_team) session.commit() flash("New team added: {0}".format(new_team.name), 'flash-success') return redirect(url_for('show_sports_teams', sport_id=sport_id)) return render_template('teams/teamsnew.html')
def post_teams(): body = request.get_json() team1 = Teams(team_id=body["team_id"], name=body["name"], teamLogo=body["teamLogo"], players=body["players"]) #p = Player(teams=user1) #p2 = Player(teams=user1) db.session.add(team1) db.session.commit() return jsonify(team1.serialize()), 200
def updateTeams(): session = CreateSession() m = session.query(Managers).all() gw = GetGameweek(session) for i in m: fplid = i.fplId r = requests.get( f"https://fantasy.premierleague.com/api/entry/{fplid}/event/{gw}/picks/" ) team = r.json() for p in team['picks']: if p['is_captain']: cap = 1 else: cap = 0 if not BenchBoost(session, i.id, gw): if p['position'] > 11: bench = 1 else: bench = 0 else: print("ay") bench = 0 plyr = Teams(gameweek=gw, managerId=i.id, playerId=int(p['element']), points=0, is_captain=cap, is_bench=bench) session.add(plyr) session.commit() session.close()
def teams(id, color): user = User.query.filter_by(id=id).first() ident = user.id nombreequipo = Teams(user_id=ident, nombre=color) db.session.add(nombreequipo) db.session.commit() success_message = 'Usuario Agregado a Equipo!' flash(success_message) return redirect(url_for('usersteams'))
def post_team(token): if type(token) == AuthError: print(token) abort(token.status_code) body = request.get_json() name = body.get('name', None) nation = body.get('nation', None) rating = body.get('rating', None) try: if rating <= 0 or rating >= 100: abort(422) new_team = Teams(name=name, nation=nation, rating=rating) new_team.insert() except Exception as e: print(e) abort(422) return jsonify({"success": True, "team": new_team.long()}), 200
def test_team_source_insert_1(self): s = Teams(id='100', stadium_name="Arrowhead Stadium", stadium_init="ah", games_played=368, city="Kansas City", week=1, team='chiefs') db.session.add(s) db.session.commit() r = db.session.query(Teams).filter_by(id='100').one() self.assertEqual(str(r.id), '100') db.session.query(Teams).filter_by(id='100').delete() db.session.commit()
def test_team_source_insert_3(self): s = Teams(id='300', stadium_name="Bank of America Stadium", stadium_init="ba", games_played=188, city="Charlotte", week=1, team='panthers') db.session.add(s) db.session.commit() r = db.session.query(Teams).filter_by(id='300').one() self.assertEqual(str(r.id), '300') db.session.query(Teams).filter_by(id='300').delete() db.session.commit()
def test_team_source_insert_2(self): s = Teams(id='200', stadium_name="AT&T Stadium", stadium_init="att", games_played=80, city="Arlington", week=1, team='cowboys') db.session.add(s) db.session.commit() r = db.session.query(Teams).filter_by(id='200').one() self.assertEqual(str(r.id), '200') db.session.query(Teams).filter_by(id='200').delete() db.session.commit()
def newTeam(): if not google.authorized: return "You are not authorized to view this page. Please log in." if request.method == 'POST': # Check csrf token if request.form['csrf_token'] != login_session.pop('csrf_token', None): return "You are not authorized to make changes" newTeam = Teams(name=request.form['name'], user_id=login_session['user_id']) session.add(newTeam) session.commit() flash('New team %s successfully created' % newTeam.name) return redirect(url_for('showTeams')) else: # Create and store csrf token before rendering template state = ''.join( random.choice(string.ascii_uppercase + string.digits) for x in range(32)) login_session['csrf_token'] = state return render_template('newTeam.html')
def create_teams(): team = load_json('teams.json') for oneTeam in team: week = oneTeam['week'] team = oneTeam['team'] city = oneTeam['city'] games_played = oneTeam['games_played'] stadium_init = oneTeam['stadium_init'] stadium_name = oneTeam['stadium_name'] id = oneTeam['id'] newTeam = Teams(id=id, stadium_name=stadium_name, stadium_init=stadium_init, games_played=games_played, city=city, team=team, week=week) # After I create the book, I can then add it to my session. db.session.add(newTeam) # commit the session to my DB. db.session.commit()
def team_create(): params = utils.flat_multi(request.form) _user = user.get_user().first() if (_user.tid is not None and _user.tid >= 0) or get_team( owner=_user.uid).first() is not None: raise WebException("You're already in a team!") verify_to_schema(TeamSchema, params) teamname = params.get("teamname") school = params.get("school") team = Teams(teamname, school, _user.uid, _user.utype != 1) with app.app_context(): db.session.add(team) db.session.commit() Users.query.filter_by(uid=_user.uid).update({"tid": team.tid}) team_activity = UserActivity(_user.uid, 1, tid=team.tid) db.session.add(team_activity) db.session.commit() session["tid"] = team.tid return {"success": 1, "message": "Success!"}
def init_main(teams = 10): for i in range(1,teams+1): country=token=name='NPC'+str(i) sshpassword='******' tmpteam=Teams(i,name,country,'team'+str(i),token,sshpassword) db.session.add(tmpteam) db.session.commit() #Add administrator #adminuser=User(1,'admin','20be459727e35f01ad0e228a2aa9579d','NPC') #Admin@123! adminuser=User('admin','Admin@123!','NPC') db.session.add(adminuser) db.session.commit() logger.info('awd database inited') print('Add administrator admin') #print(User.query.all()) #print(Teams.query.all()) try: j=1 for i in open('users.txt').read().splitlines(): username , userpass = i.split(' ') db.session.add(User(username , userpass , 'team'+str(j))) Teams.query.filter(Teams.teamcontainer=='team'+str(j)).update({Teams.name: username}) j+=1 db.session.commit() except: print('Create user error') pass
def init_main(npcteams=3): userlist = [] teamlist = [] npcpassword = '******' for i in open('users.txt').read().splitlines(): if len(i) > 10: team, username, userpass = i.split(' ') userlist.append([team, username, userpass]) teamlist.append(team) for i in xrange(npcteams): team, username, userpass = '******' + str(i), 'NPC' + str(i), npcpassword userlist.append([team, username, userpass]) teamlist.append(team) teamlist = list(set(teamlist)) #print userlist #print teamlist,list(set(teamlist)) for i in teamlist: db.session.add( Teams(i, '', make_token_str(i), make_token_str(i))) #name,country,token,sshpassword db.session.commit() teams = Teams.query.all() teamdic = {} for i in teams: teamdic[i.name] = i.id #print teamdic print 'TeamId\tTeamName\tUserName\tUserPassword' for i in userlist: team, username, userpass = i teamid = teamdic[team.decode('utf-8')] print '%d\t%s\t%s\t%s' % (teamid, team, username, userpass) db.session.add(User(username, userpass, teamid)) db.session.commit()
def addTeams(): #Tables with each teams win-loss record, basic stats for each of the last two seasons teams = ['ATL', 'BOS', 'NJN', 'CHA', 'CHI', 'CLE', 'DAL', 'DEN', 'DET', 'GSW', 'HOU', 'IND', 'LAC', 'LAL', 'MEM', 'MIA', 'MIL', 'MIN', 'NOH', 'NYK', 'OKC', 'ORL', 'PHI', 'PHO', 'POR', 'SAC', 'SAS', 'TOR', 'UTA', 'WAS'] teams201718 = [] teams201617 = [] for team in range(30): html = urlopen("https://www.basketball-reference.com/teams/%s/stats_per_game_totals.html" % teams[team]) teamObj = BeautifulSoup(html, "lxml") team201819 = teamObj.tbody.find("tr") team201718 = team201819.find_next("tr") team201617 = team201718.find_next("tr") teamstats = team201718.findAll("td") teamstats1 = team201617.findAll("td") name, name1 = teamstats[1].get_text(), teamstats1[1].get_text() wins, wins1 = teamstats[2].get_text(), teamstats1[2].get_text() losses, losses1 = teamstats[3].get_text(), teamstats1[3].get_text() points, points1 = teamstats[32].get_text(), teamstats1[32].get_text() rbs, rbs1 = teamstats[26].get_text(), teamstats1[26].get_text() assts, assts1 = teamstats[27].get_text(), teamstats1[27].get_text() stattuple, stattuple1 = (name, wins, losses, points, rbs, assts), (name1, wins1, losses1, points1, rbs1, assts1) teams201718.append(stattuple) #teams201617.append(stattuple1) # inserts team data in the database for 17-18 season for team in teams201718: team_stats = Teams(name=team[0], wins=team[1], losses=team[2], points=team[3], rebounds=team[4], assists=team[5]) db.session.add(team_stats) # commits the changes made to the database db.session.commit()
def _get_team(): team = Teams() return team
from sqlalchemy import create_engine, asc from sqlalchemy.orm import sessionmaker from models import Base, Users, Teams, Players engine = create_engine('sqlite:///baseball.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() # Populate baseball.db with teams and players # Team Scorpions scorpions = Teams(name="Scorpions") session.add(scorpions) session.commit() # Scorpions Roster gutierrez = Players(name="Randal Gutierrez", position="1B", number="44", handedness="L", teams=scorpions) session.add(gutierrez) session.commit() walsh = Players(name="Horace Walsh", position="2B", number="12", handedness="R", teams=scorpions) session.add(walsh) session.commit() jones = Players(name="Steve Jones", position="3B", number="71", handedness="R", teams=scorpions)