Exemple #1
0
def create_pick(request, gameno):
    try:
        g = Game.objects.get(id=gameno)
    except Game.DoesNotExist:
        g = None

    if Pick.objects.filter(user=request.session.get('_auth_user_id'), game=gameno).exists():
        messages.add_message(request, messages.INFO, 'You already have a pick for this game')
        return HttpResponseRedirect('/mypicks')

    if datetime.now() - Game.objects.get(id=gameno).deadline > timedelta(seconds=0):
        messages.add_message(request, messages.INFO, 'Sorry, the deadline has passed to pick for that game')
        return HttpResponseRedirect('/mypicks')

    if g:
        away = Team.objects.get(call=g.away)
        home = Team.objects.get(call=g.home)
        if request.method == 'POST':
            if not request.POST['pick']:
                messages.add_message(request, messagees.INFO, 'You did not make a selection!')
                return HttpResponseRedirect('/pick/%i' % gameno)
            p = Pick(user=request.session.get('_auth_user_id'), game=gameno, week=g.week, pick=request.POST['pick'])
            p.save()
            messages.add_message(request, messages.INFO, 'Pick added!')
            return HttpResponseRedirect('/mypicks')
        else:
            form = Form()

    return render_to_response('pick.html', {'form':form, 'away':away, 'home':home, 'gameid':gameno},
                              context_instance=RequestContext(request))
Exemple #2
0
class UserPicks():
    @pickBp.route("/addPick", methods=['POST'])
    def addPick():
        json_data = request.get_json(force=True)
        if not json_data:
            return jsonify({'message': 'No input data provided'}), 400

    pick = Pick(username=json_data['username'], picks=json_data['picks'])

    db.session.add(pick)
    db.session.commit()
Exemple #3
0
    def post(self):
        try:
            choice0 = self.request.POST[u'choice0'].strip()
            choice1 = self.request.POST[u'choice1'].strip()
            choice2 = self.request.POST[u'choice2'].strip()
            choiceid0 = self.request.POST[u'choiceid0'].strip()
            choiceid1 = self.request.POST[u'choiceid1'].strip()
            choiceid2 = self.request.POST[u'choiceid2'].strip()

            if not choice0 or not choiceid0:
                raise PickException(u'Hey! feed atleast one valentine pick.')

            if not choice1 or not choiceid1:
                raise PickException(u'Hey! feed atleast one valentine pick.')

            if not choice2 or not choiceid2:
                raise PickException(u'Hey! feed atleast one valentine pick.')

            date = datetime.datetime.now()

            pick = Pick(
                user_id=self.user.user_id,
                user_name=self.user.name,
                choice0=choice0,
                choice1=choice1,
                choice2=choice2,
                choiceid0=choiceid0,
                choiceid1=choiceid1,
                choiceid2=choiceid2,
                date=date,
            )
            pick.put()


#            self.set_message(type=u'success', content=u'Added your pick. ')
        except PickException, e:
            self.set_message(type=u'error', content=unicode(e))
Exemple #4
0
    def post(self):
        try:
            choice0 = self.request.POST[u'choice0'].strip()
            choice1 = self.request.POST[u'choice1'].strip()
            choice2 = self.request.POST[u'choice2'].strip()
            choiceid0 = self.request.POST[u'choiceid0'].strip()
            choiceid1 = self.request.POST[u'choiceid1'].strip()
            choiceid2 = self.request.POST[u'choiceid2'].strip()
            
            if not choice0 or not choiceid0:
                raise PickException(u'Hey! feed atleast one valentine pick.')

            if not choice1 or not choiceid1:
                raise PickException(u'Hey! feed atleast one valentine pick.')

            if not choice2 or not choiceid2:
                raise PickException(u'Hey! feed atleast one valentine pick.')

            date = datetime.datetime.now()

            pick = Pick(
                user_id=self.user.user_id,
                user_name=self.user.name,
                choice0=choice0,
                choice1=choice1,
                choice2=choice2,
                choiceid0=choiceid0,
                choiceid1=choiceid1,
                choiceid2=choiceid2,
                date=date,
            )
            pick.put()

#            self.set_message(type=u'success', content=u'Added your pick. ')
        except PickException, e:
            self.set_message(type=u'error', content=unicode(e))
Exemple #5
0
def show_confirm_form():

    ##Check if user is logged in

    if 'user_id' not in session:
        flash("Please login first!", "danger")
        return redirect(f'/login?return=/home')

    form =ConfirmForm()

    game_date = session['game_date']
    rotation_number = session['rotation_number']
    moneyline = session['moneyline']
    team = session['team']
    opponent = session['opponent']
    risk_amount = session['risk_amount']
    game_id = session['game_id']
    side = session['side']
    user_id = session['user_id']

    if moneyline<-99:
        win_amount = round( risk_amount * 100 / abs(moneyline),2)
        pick_odds_pct = round(abs( moneyline) / (abs(moneyline) + 100),3)
        print(pick_odds_pct)
    else:
        win_amount = round((risk_amount * moneyline * .01),2)
        pick_odds_pct = round( 100 / (abs(moneyline) + 100),3)
        print(pick_odds_pct) 



    if form.validate_on_submit():

        new_pick = Pick( user_id=user_id, game_id=game_id,risk_amount = risk_amount, to_win_amount = win_amount, pick = team, side = side, pick_odds_amer = moneyline, pick_odds_pct = pick_odds_pct, pick_status = 'STATUS_SCHEDULED')
        db.session.add(new_pick)
        db.session.commit()
        flash('Pick Created!', 'success')
        return redirect ('/')

    return render_template("confirm_pick.html", game_date = game_date, rotation_number = rotation_number, team = team, moneyline = moneyline, opponent = opponent, risk_amount = risk_amount, win_amount = win_amount, form=form)
Exemple #6
0
    def get(self):
        user = users.get_current_user()
        throwaway = datetime.datetime.strptime('20110101', '%Y%m%d')
        curr_date = datetime.datetime.strptime(self.request.get('date'),
                                               "%Y%m%d")

        #if curr_date is None:
        sport = self.request.get('sport')
        #sport = 'nfl'

        if sport == "nfl":
            qry = Event.query().filter(
                Event.sport == "nfl", Event.date > curr_date).order(Event.date)
            week = qry.fetch(1)[0].week
            #logging.info(week)
            curr_games_qry = Event.query().filter(Event.week == week)
        else:
            curr_games_qry = Event.query().filter(Event.date == curr_date,
                                                  Event.sport == 'nba')
        curr_games_raw = curr_games_qry.fetch()
        #logging.info(curr_games_raw)
        #logging.info(curr_games_raw)
        responseData = []
        for curr_game in curr_games_raw:

            #curr_pick = Pick.query().filter(Pick.event.id() == curr_game.key.id())
            start_time = curr_game.start_time - datetime.timedelta(
                hours=5)  # to ET
            start_time = start_time.strftime("%H:%M:%S")
            winner = curr_game.outcome.winner
            if winner is not None:
                winner = winner.id()
            game_data = {
                'time': start_time,
                'sport': sport,
                'game_id': curr_game.key.id(),
                'home': curr_game.options[0].get().tri_code,
                'home_id': curr_game.options[0].id(),
                'away': curr_game.options[1].get().tri_code,
                'away_id': curr_game.options[1].id(),
                'winner': winner
            }
            if sport == "nfl":
                game_data['week'] = week
                #logging.info("HELLO")

                game_data['date'] = curr_game.date.strftime("%Y%m%d")
            if len(curr_game.outcome.scores) > 0:
                game_data['scores'] = curr_game.outcome.scores
            #start_time = curr_game.start_time.strftime("%H:%M:%S")
            if user:
                curr_pick_qry = Pick.query().filter(
                    Pick.user_id == user.user_id())
                curr_pick_qry = curr_pick_qry.filter(
                    Pick.event == curr_game.key)
                #print curr_pick_qry
                curr_pick = curr_pick_qry.fetch()
                if len(curr_pick) > 0:
                    game_data['current_pick'] = curr_pick[0].pick.get(
                    ).tri_code
                    responseData.append(game_data)
                    #responseData.append({'time': start_time, 'game_id': curr_game.key.id(), 'home': curr_game.options[0].get().tri_code, 'home_id': curr_game.options[0].id(), 'away': curr_game.options[1].get().tri_code, 'away_id': curr_game.options[1].id(), 'current_pick': curr_pick[0].pick.get().tri_code, 'winner': curr_game.outcome.winner.id()})
                else:
                    responseData.append(game_data)
                    #responseData.append({'time': start_time, 'game_id': curr_game.key.id(), 'home': curr_game.options[0].get().tri_code, 'home_id': curr_game.options[0].id(), 'away': curr_game.options[1].get().tri_code, 'away_id': curr_game.options[1].id(), 'winner': curr_game.outcome.winner.id()})
            else:
                responseData.append(game_data)
        # MAGIC
        self.response.out.write(json.dumps(responseData))