Ejemplo n.º 1
0
 def post(self):
     user = users.get_current_user()
     if user:
         email_address = user.nickname()
         cssi_user = Users.get_by_id(user.user_id())
         signout_link_html = '<a href="%s">Sign Out</a>' % users.create_logout_url(
             '/')
     name = self.request.get('name')
     timer = 0
     if self.request.get("timer") == 'yes':
         timer = self.request.get('timer1')
     background_image = self.request.get('background_image')
     player1 = self.request.get('player1')
     player2 = self.request.get('player2')
     player3 = self.request.get('player3')
     player4 = self.request.get('player4')
     player5 = self.request.get('player5')
     player6 = self.request.get('player6')
     player7 = self.request.get('player7')
     player8 = self.request.get('player8')
     player9 = self.request.get('player9')
     player10 = self.request.get('player10')
     player11 = self.request.get('player11')
     player12 = self.request.get('player12')
     player13 = self.request.get('player13')
     player14 = self.request.get('player14')
     player15 = self.request.get('player15')
     player16 = self.request.get('player16')
     round0 = [
         player1, player2, player3, player4, player5, player6, player7,
         player8, player9, player10, player11, player12, player13, player14,
         player15, player16
     ]
     if background_image == '':
         background_image = self.request.get('background')
     bracket_style_font = self.request.get('style_font')
     bracket_style_color = self.request.get('style_color')
     if self.request.get('loser_bracket') == 'yes':
         loser_bracket = True
         print loser_bracket
     else:
         loser_bracket = False
     if self.request.get('public') == 'yes':
         public = True
     else:
         public = False
     new_tournament = Tournaments(
         name=name,
         background_image=background_image,
         background_color=bracket_style_color,
         background_font=bracket_style_font,
         loser_bracket=loser_bracket,
         public=public,
         creator=cssi_user.first_name,
         round0=round0,
     )
     viewer = new_tournament.put()
     view_id = viewer.urlsafe()
     players = Profiles().query().fetch()
     self.redirect('/tournamentViewer?id=' + view_id)
Ejemplo n.º 2
0
    def swap_tracker(user_id):

        if request.args.get('history') == 'true':
            trmnts = Tournaments.get_history(user_id=user_id)
        else:
            trmnts = Tournaments.get_live_upcoming(user_id=user_id)

        swap_trackers = []

        if trmnts is not None:

            for trmnt in trmnts:
                json = actions.swap_tracker_json(trmnt, user_id)
                swap_trackers.append(json)

        return jsonify(swap_trackers)
Ejemplo n.º 3
0
def add_tournament():
    body = request.get_json()
    db.session.add(
        Tournaments(name=body['name'],
                    address=body['address'],
                    start_at=datetime(*body['start_at']),
                    end_at=datetime(*body['end_at']),
                    longitude=None,
                    latitude=None))
    db.session.commit()
    search = {'name': body['name'], 'start_at': datetime(*body['start_at'])}
    return jsonify(
        Tournaments.query.filter_by(**search).first().serialize()), 200
Ejemplo n.º 4
0
    def update_tournaments():

        # Update from days ago or hours ago
        span = request.args.get('span')
        amount = request.args.get('amount')

        if None not in [span, amount]:
            args = f'?span={span}&amount={amount}'
        else: args = ''

        resp = requests.get( 
            f"{os.environ['POKERSOCIETY_HOST']}/swapprofit/update{args}" )
        if not resp.ok:
            raise APIException( resp.content.decode("utf-8")[-233:] , 500)


        data = resp.json()
        for d in data:

            # TOURNAMENTS
            trmntjson = d['tournament']
            trmnt = Tournaments.query.get( trmntjson['id'] )
            if trmnt is None:
                db.session.add( Tournaments(
                    **{col:val for col,val in trmntjson.items()} ))
            else:
                for col,val in trmntjson.items():
                    if getattr(trmnt, col) != val:
                        setattr(trmnt, col, val)
                
            # FLIGHTS
            for flightjson in d['flights']:
                flight = Flights.query.get( flightjson['id'] )
                if flight is None:
                    db.session.add( Flights(
                        **{col:val for col,val in flightjson.items()} ))
                else:
                    for col,val in flightjson.items():
                        if getattr(flight, col) != val:
                            setattr(flight, col, val)

            db.session.commit()
Ejemplo n.º 5
0
    def swap_tracker(user_id):

        trmnts = Tournaments.get_live(user_id=user_id)
        if trmnts is None:
            raise APIException(
                'You have not bought into any current tournaments', 404)

        list_of_swap_trackers = []

        for trmnt in trmnts:

            my_buyin = Buy_ins.get_latest(user_id=user_id,
                                          tournament_id=trmnt.id)
            if my_buyin is None:
                raise APIException('Can not find buyin', 404)

            swaps = Swaps.query.filter_by(sender_id=user_id,
                                          tournament_id=trmnt.id)
            if swaps is None:
                return jsonify(
                    {'message': 'You have no live swaps in this tournament'})

            swaps = [{
                'swap':
                swap.serialize(),
                'buyin':
                (Buy_ins.get_latest(user_id=swap.recipient_id,
                                    tournament_id=trmnt.id).serialize())
            } for swap in swaps]

            list_of_swap_trackers.append({
                'tournament': trmnt.serialize(),
                'my_buyin': my_buyin.serialize(),
                'swaps': swaps
            })

        return jsonify(list_of_swap_trackers)
Ejemplo n.º 6
0
def run():
    Transactions.query.delete()

    # Casinos.query.delete()
    # Results.query.delete()
    Messages.query.delete()
    # Chats.query.delete()
    Devices.query.delete()
    Buy_ins.query.delete()
    Swaps.query.delete()
    Flights.query.delete()
    Tournaments.query.delete()
    # Casinos.query.delete()
    Profiles.query.delete()
    Users.query.delete()
    Casinos.query.delete()

    # db.session.execute("ALTER SEQUENCE casinos_id_seq RESTART")
    # db.session.execute("ALTER SEQUENCE results_id_seq RESTART")
    # db.session.execute("ALTER SEQUENCE casinos RESTART")
    db.session.execute("ALTER SEQUENCE users_id_seq RESTART")

    db.session.execute("ALTER SEQUENCE buy_ins_id_seq RESTART")
    db.session.execute("ALTER SEQUENCE flights_id_seq RESTART")
    db.session.execute("ALTER SEQUENCE tournaments_id_seq RESTART")
    db.session.execute("ALTER SEQUENCE swaps_id_seq RESTART")
    db.session.execute("ALTER SEQUENCE transactions_id_seq RESTART")
    db.session.execute("ALTER SEQUENCE devices_id_seq RESTART")
    db.session.execute("ALTER SEQUENCE chats_id_seq RESTART")
    db.session.execute("ALTER SEQUENCE messages_id_seq RESTART")


    # db.session.commit()


    # LOAD FILES
    # actions.load_tournament_file()

    # latest_trmnt_id = db.session.query( func.max( Tournaments.id)).scalar()
    # db.session.execute(
    #     "ALTER SEQUENCE tournaments_id_seq RESTART WITH " + 
    #     str(latest_trmnt_id + 1) )

    # latest_flight_id = db.session.query( func.max( Flights.id)).scalar()
    # db.session.execute(
    #     "ALTER SEQUENCE flights_id_seq RESTART WITH " +
    #     str(latest_flight_id + 1) )


    d0 = datetime.utcnow() - timedelta(hours=17, minutes=1)
    d1 = datetime.utcnow() + timedelta(minutes=5)
    d2 = datetime.utcnow() - timedelta(hours=16, minutes=59)
    d3 = datetime.utcnow() + timedelta(days=300)
    d4 = datetime.utcnow() + timedelta(days=301)

    oneCasino= Casinos(
        id='USFL001',
        name='Seminole Hard Rock Hotel & Casino',
        address='1 Seminole Way',
        city='Davie',
        state='FL',
        zip_code='33314',
        latitude=26.0510,
        longitude=-80.2097,
        time_zone='America/New_York',
    )
    db.session.add(oneCasino)
    

    # Demo Past Tournament
    past = Tournaments(
        casino=oneCasino,
        name='Past Demo Event #1',
        start_at= d0,
        buy_in_amount=100, 
        results_link='lol',
    )
    db.session.add(past)
    flight1_past = Flights(
        start_at=past.start_at,
        tournament=past,
    )
    db.session.add(flight1_past)
 


    # Apple Demo Tournament and Flights
    demo1 = Tournaments(
        casino=oneCasino,
        name="Apple Demo Event '22",
        start_at= d3,
        buy_in_amount=100,
        starting_stack = 5000,
        blinds= 20,
        structure_link = 'https://www.seminolehardrockpokeropen.com/wp-content/uploads/2021/03/2021-April-2-9-30-6P-Fri-150-Deep-Stack-Green-Chip-Bounty-88-Entry-Maxv....pdf'
    )
    db.session.add(demo1)
    flight1_demo1 = Flights(
        start_at=demo1.start_at,
        tournament=demo1,
        day='1A'
    )
    db.session.add(flight1_demo1)
    flight2_demo1 = Flights(
        start_at=demo1.start_at + timedelta(hours=6),
        tournament=demo1,
        day='1B'
    )
    db.session.add(flight2_demo1)


    # Android Demo Tournament and Flights
    demo2 = Tournaments(
        casino=oneCasino,
        name="Android Demo Event '22",
        start_at= d4,
        buy_in_amount=100,
        starting_stack = 4000,
        blinds= 21,
        structure_link = 'https://www.seminolehardrockpokeropen.com/wp-content/uploads/2021/03/2021-April-13-14-11A-7P-140-Showdown-Mega-Turbo-Satellite-Event-.pdf'
    )
    db.session.add(demo2)
    flight1_demo2 = Flights(
        start_at=demo2.start_at,
        tournament=demo2,
        day='1A'
    )
    db.session.add(flight1_demo2)
    flight2_demo2 = Flights(
        start_at=demo2.start_at + timedelta(hours=6),
        tournament=demo2,
        day="1B"
    )
    db.session.add(flight2_demo2)



    ########################
    #  USERS AND PROFILES
    ########################

    # MY ADMIN ACCOUNT
    gabe = Users(
        id=1,
        email='*****@*****.**',
        password=sha256('casper5'),
        status='valid'
    )
    db.session.add(gabe)
    gabe = Profiles(
        id=1,
        first_name='Gabriel', 
        last_name='Herndon',
        nickname='',
        hendon_url=None,
        profile_pic_url='https://d1we5yax8fyln6.cloudfront.net/sites/stage32.com/files/imagecache/head_shot_500/headshots/3a160ee8689722fd93f3999b10d2b8d9_1428609546_l.jpg',
        user=gabe,
        roi_rating=0.0,
        swap_rating=0.0
    )
    db.session.add(gabe)
    db.session.add( Transactions(
        coins=5,
        user=gabe
    ))
    
    
    # TEST ACCOUNT 1
    alice = Users(
        id=2,
        email='*****@*****.**',
        password=sha256('Casper5!'),
        status='valid'
    )
    db.session.add(alice)
    alice = Profiles(
        id=2,
        first_name='Allison', 
        last_name='Avery',
        nickname='Alice',
        user=alice,
        profile_pic_url='https://media.heartlandtv.com/images/Alice1.PNG',
        roi_rating=0.0,
        swap_rating=0.0
    )
    db.session.add(alice)
    db.session.add( Transactions(
        coins=5,
        user=alice
    ))

    # TEST ACCOUNT 1 - BUY INS

    a_buyinPast = Buy_ins(
        status='active',
        # tournament_id = past.id,
        chips = 1000,
        table = 5,
        seat = 10,
        created_at = datetime.utcnow(),
        updated_at = datetime.utcnow(),
        user = alice,
        flight = flight1_past,
        place='3rd',
        winnings=5000
    )
    db.session.add(a_buyinPast)
    
    a_buyin1 = Buy_ins(
        status='active',
        # tournament_id = demo1.id,
        chips = 15000,
        table = 7,
        seat = 4,
        created_at = datetime.utcnow(),
        updated_at = datetime.utcnow(),
        user = alice,
        flight = flight1_demo1
    )
    db.session.add(a_buyin1)

    a_buyin2 = Buy_ins(
        status='active',
        # tournament_id = demo2.id,
        chips = 15000,
        table = 7,
        seat = 4,
        created_at = datetime.utcnow(),
        updated_at = datetime.utcnow(),
        user = alice,
        flight = flight1_demo2
    )
    db.session.add(a_buyin2)


    # TEST ACCOUNT 2
    bob = Users(
        id=3,
        email='*****@*****.**',
        password=sha256('Casper5!'),
        status='valid'
    )
    db.session.add(bob)
    bob = Profiles(
        id=3,
        first_name='Bobert', 
        last_name='Benderson',
        nickname='Bob',
        profile_pic_url='https://www.bobross.com/content/bob_ross_img.png',
        user=bob,
        roi_rating=0.0,
        swap_rating=0.0
    )
    db.session.add(bob)
    db.session.add( Transactions(
        coins=5,
        user=bob
    ))

    # TEST ACCOUNT 2 - BUY INS
    b_buyinPast = Buy_ins(
        status='active',
        # tournament_id = past.id,
        chips = 10000,
        table = 15,
        seat = 6,
        created_at = datetime.utcnow(),
        updated_at = datetime.utcnow(),
        user = bob,
        flight = flight1_past,
        place='4th',
        winnings=3000
    )
    db.session.add(b_buyinPast)

    b_buyin1 = Buy_ins(
        status='active',

        # tournament_id = demo1.id,
        chips = 12000,
        table = 9,
        seat = 3,
        created_at = datetime.utcnow(),
        updated_at = datetime.utcnow(),
        user = bob,
        flight = flight2_demo1
    )
    db.session.add(b_buyin1)

    b_buyin2 = Buy_ins(
        status='active',
        # tournament_id = demo2.id,
        chips = 12000,
        table = 9,
        seat = 3,
        created_at = datetime.utcnow(),
        updated_at = datetime.utcnow(),
        user = bob,
        flight = flight2_demo2
    )
    db.session.add(b_buyin2)


    # APPLE TEST ACCOUNT
    apple = Users(
        id=4,
        email='*****@*****.**',
        password=sha256('AppleTest07?'),
        status='valid'
    )
    db.session.add(apple)
    apple = Profiles(
        id=4,
        first_name='Apple',
        last_name='Demo Account',
        nickname='',
        hendon_url=None,
        profile_pic_url='https://www.macworld.co.uk/cmsdata/features/3793151/apple_logo_thumb800.jpg',
        user=apple,
        roi_rating=0.0,
        swap_rating=0.0
    )
    db.session.add(apple)
    db.session.add( Transactions(
        coins=5,
        user=apple
    ))

    # APPLE TEST ACCOUNT - BUYINS
    app_buyinPast = Buy_ins(
        status='active',
        # tournament_id = past.id,
        chips = 3000,
        table = 2,
        seat = 1,
        created_at = datetime.utcnow(),
        updated_at = datetime.utcnow(),
        user = apple,
        flight = flight1_past,
        place='6th',
        winnings=500
    )
    db.session.add(app_buyinPast)

    app_buyin1 = Buy_ins(
        status='active',
        # tournament_id = demo1.id,
        chips = 10000,
        table = 17,
        seat = 2,
        created_at = datetime.utcnow(),
        updated_at = datetime.utcnow(),
        user = apple,
        flight = flight1_demo1
    )
    db.session.add(app_buyin1)

 ########## APPLE PAST TOURNAMENT ###########


    s1 = Swaps(
        tournament=past,
        sender_user=apple,
        recipient_user=alice,
        percentage=10,
        status='agreed',
        # due_at=(past.start_at + timedelta(days=4))
    )
    s2 = Swaps(
        tournament=past,
        sender_user=alice,
        recipient_user=apple,
        percentage=10,
        status='agreed',
        # due_at=(past.start_at + timedelta(days=4)),
        counter_swap=s1
    )
    s1.counter_swap = s2
    db.session.add_all([s1, s2])
  

    s1 = Swaps(
        tournament=past,
        sender_user=apple,
        recipient_user=alice,
        percentage=5,
        status='canceled',
        # due_at=(past.start_at + timedelta(days=4))
    )
    s2 = Swaps(
        tournament=past,
        sender_user=alice,
        recipient_user=apple,
        percentage=7,
        status='canceled',
        # due_at=(past.start_at + timedelta(days=4)),
        counter_swap=s1
    )
    s1.counter_swap = s2
    db.session.add_all([s1, s2])



    s1 = Swaps(
        tournament=past,
        sender_user=apple,
        recipient_user=bob,
        percentage=6,
        status='rejected',
        # due_at=(past.start_at + timedelta(days=4))
    )
    s2 = Swaps(
        tournament=past,
        sender_user=bob,
        recipient_user=apple,
        percentage=21,
        status='rejected',
        # due_at=(past.start_at + timedelta(days=4)),
        counter_swap=s1
    )
    s1.counter_swap = s2
    db.session.add_all([s1, s2])





    ########## APPLE CURRENT TOURNAMENT ###########

    s1 = Swaps(
        tournament=demo1,
        sender_user=apple,
        recipient_user=alice,
        percentage=5,
        status='pending',
        # due_at=(demo2.start_at + timedelta(days=4))
    )
    s2 = Swaps(
        tournament=demo1,
        sender_user=alice,
        recipient_user=apple,
        percentage=7,
        status='incoming',
        # due_at=(demo2.start_at + timedelta(days=4)),
        counter_swap=s1
    )
    s1.counter_swap = s2
    db.session.add_all([s1, s2])

    s1 = Swaps(
        tournament=demo1,
        sender_user=apple,
        recipient_user=alice,
        percentage=5,
        status='agreed',
        # due_at=(demo2.start_at + timedelta(days=4))
    )
    s2 = Swaps(
        tournament=demo1,
        sender_user=alice,
        recipient_user=apple,
        percentage=7,
        status='agreed',
        # due_at=(demo2.start_at + timedelta(days=4)),
        counter_swap=s1
    )
    s1.counter_swap = s2
    db.session.add_all([s1, s2])
  

    s1 = Swaps(
        tournament=demo1,
        sender_user=apple,
        recipient_user=alice,
        percentage=15,
        status='canceled',
        # due_at=(demo2.start_at + timedelta(days=4))
    )
    s2 = Swaps(
        tournament=demo1,
        sender_user=alice,
        recipient_user=apple,
        percentage=17,
        status='canceled',
        # due_at=(demo2.start_at + timedelta(days=4)),
        counter_swap=s1
    )
    s1.counter_swap = s2
    db.session.add_all([s1, s2])



    s1 = Swaps(
        tournament=demo1,
        sender_user=apple,
        recipient_user=bob,
        percentage=6,
        status='rejected',
        # due_at=(demo2.start_at + timedelta(days=4))
    )
    s2 = Swaps(
        tournament=demo1,
        sender_user=bob,
        recipient_user=apple,
        percentage=21,
        status='rejected',
        # due_at=(demo2.start_at + timedelta(days=4)),
        counter_swap=s1
    )
    s1.counter_swap = s2
    db.session.add_all([s1, s2])

  


    # ANDORID TEST ACCOUNT
    android = Users(
        id=5,
        email='*****@*****.**',
        password=sha256('AndroidTest08?'),
        status='valid'
    )
    db.session.add(android)
    android = Profiles(
        id=5,
        first_name='Android', 
        last_name='Demo Account',
        nickname='',
        hendon_url=None,
        profile_pic_url='https://1000logos.net/wp-content/uploads/2016/10/Android-Logo.png',
        user=android,
        roi_rating=0.0,
        swap_rating=0.0
    )
    db.session.add(android)
    db.session.add( Transactions(
        coins=5,
        user=android
    ))
    
    # ANDORID TEST ACCOUNT - BUYINS
    and_buyinPast = Buy_ins(
        status='active',
        # tournament_id = past.id,
        chips = 2000,
        table = 14,
        seat = 2,
        created_at = datetime.utcnow(),
        updated_at = datetime.utcnow(),
        user = android,
        flight = flight1_past,
        place='7th',
        winnings=400
    )
    db.session.add(and_buyinPast)

    and_buyin1 = Buy_ins(
        status='active',
        # tournament_id = demo2.id,
        chips = 10000,
        table = 17,
        seat = 2,
        created_at = datetime.utcnow(),
        updated_at = datetime.utcnow(),
        user = android,
        flight = flight1_demo2
    )
    db.session.add(and_buyin1)



    ########## ANDROID PAST TOURNAMENT ###########


    s1 = Swaps(
        tournament=past,
        sender_user=android,
        recipient_user=alice,
        percentage=10,
        status='agreed',
        # due_at=(past.start_at + timedelta(days=4))
    )
    s2 = Swaps(
        tournament=past,
        sender_user=alice,
        recipient_user=android,
        percentage=10,
        status='agreed',
        # due_at=(past.start_at + timedelta(days=4)),
        counter_swap=s1
    )
    s1.counter_swap = s2
    db.session.add_all([s1, s2])
  

    s1 = Swaps(
        tournament=past,
        sender_user=android,
        recipient_user=alice,
        percentage=5,
        status='canceled',
        # due_at=(past.start_at + timedelta(days=4))
    )
    s2 = Swaps(
        tournament=past,
        sender_user=alice,
        recipient_user=android,
        percentage=7,
        status='canceled',
        # due_at=(past.start_at + timedelta(days=4)),
        counter_swap=s1
    )
    s1.counter_swap = s2
    db.session.add_all([s1, s2])



    s1 = Swaps(
        tournament=past,
        sender_user=android,
        recipient_user=bob,
        percentage=6,
        status='rejected',
        # due_at=(past.start_at + timedelta(days=4))
    )
    s2 = Swaps(
        tournament=past,
        sender_user=bob,
        recipient_user=android,
        percentage=21,
        status='rejected',
        # due_at=(past.start_at + timedelta(days=4)),
        counter_swap=s1
    )
    s1.counter_swap = s2
    db.session.add_all([s1, s2])





    ########## ANDROID CURRENT TOURNAMENT ###########

    s1 = Swaps(
        tournament=demo2,
        sender_user=android,
        recipient_user=alice,
        percentage=5,
        status='pending',
        # due_at=(demo2.start_at + timedelta(days=4))
    )
    s2 = Swaps(
        tournament=demo2,
        sender_user=alice,
        recipient_user=android,
        percentage=7,
        status='incoming',
        # due_at=(demo2.start_at + timedelta(days=4)),
        counter_swap=s1
    )
    s1.counter_swap = s2
    db.session.add_all([s1, s2])

    s1 = Swaps(
        tournament=demo2,
        sender_user=android,
        recipient_user=alice,
        percentage=5,
        status='agreed',
        # due_at=(demo2.start_at + timedelta(days=4))
    )
    s2 = Swaps(
        tournament=demo2,
        sender_user=alice,
        recipient_user=android,
        percentage=7,
        status='agreed',
        # due_at=(demo2.start_at + timedelta(days=4)),
        counter_swap=s1
    )
    s1.counter_swap = s2
    db.session.add_all([s1, s2])
  

    s1 = Swaps(
        tournament=demo2,
        sender_user=android,
        recipient_user=alice,
        percentage=15,
        status='canceled',
        # due_at=(demo2.start_at + timedelta(days=4))
    )
    s2 = Swaps(
        tournament=demo2,
        sender_user=alice,
        recipient_user=android,
        percentage=17,
        status='canceled',
        # due_at=(demo2.start_at + timedelta(days=4)),
        counter_swap=s1
    )
    s1.counter_swap = s2
    db.session.add_all([s1, s2])



    s1 = Swaps(
        tournament=demo2,
        sender_user=android,
        recipient_user=bob,
        percentage=6,
        status='rejected',
        # due_at=(demo2.start_at + timedelta(days=4))
    )
    s2 = Swaps(
        tournament=demo2,
        sender_user=bob,
        recipient_user=android,
        percentage=21,
        status='rejected',
        # due_at=(demo2.start_at + timedelta(days=4)),
        counter_swap=s1
    )
    s1.counter_swap = s2
    db.session.add_all([s1, s2])


    db.session.execute("ALTER SEQUENCE tournaments_id_seq RESTART WITH 100")
    db.session.execute("ALTER SEQUENCE flights_id_seq RESTART WITH 100")
# Give room for Swap Profit to add mock tournaments
    db.session.execute("ALTER SEQUENCE users_id_seq RESTART WITH 6")
    db.session.commit()


    return
Ejemplo n.º 7
0
def load_tournament_file():



    path = os.environ['APP_PATH']
    with open( path + '/src/jsons/tournaments.json' ) as f:
        data = json.load( f )


    # casino cache so not to request for same casinos
    path_cache = os.environ['APP_PATH'] + '/src/jsons/casinos.json'
    if os.path.exists( path_cache ):
        with open( path_cache ) as f:
            cache = json.load(f)
    else: cache = {}


    for r in data:
        
        # Do not add these to Swap Profit
        if r['Tournament'].strip() == '' or \
        'satelite' in r['Tournament'].lower() or \
        r['Results Link'] == False:
            continue

        trmnt = Tournaments.query.get( r['Tournament ID'] )
        trmnt_name, flight_day = utils.resolve_name_day( r['Tournament'] )
        start_at = datetime.strptime(
            r['Date'][:10] + r['Time'], 
            '%Y-%m-%d%H:%M:%S' )

        trmntjson = { 
            'id': r['Tournament ID'],
            'name': trmnt_name, 
            'start_at': start_at,
            'results_link': str( r['Results Link'] ).strip()
        }
        flightjson = {
            'start_at':start_at,
            'day': flight_day
        }


        if trmnt is None:

            casino = cache.get( r['Casino ID'] )
            print("THIS CASINO", f'{casino}') 
            trmntjson = {
                **trmntjson,
                'casino': casino['name'],
                'address': casino['address'].strip(),
                'city': casino['city'].strip(),
                'state': casino['state'].strip(),
                'zip_code': str( casino['zip_code'] ).strip(),
                'longitude': float( casino['longitude'] ),
                'latitude': float( casino['latitude'] )
            }

            # Create tournament
            trmnt = Tournaments(
                **trmntjson
            )
            db.session.add( trmnt )
            db.session.flush()
                     
            # Create flight
            db.session.add( Flights( 
                tournament_id=trmnt.id,
                **flightjson
            ))

        else:
            # Create flight
            db.session.add( Flights( 
                tournament_id=trmnt.id,
                **flightjson
            ))
            

        db.session.commit()

    return True


    '''
    {
        "api_token": 1
        "tournament_id": 45,
        "tournament_buyin": 150,
        "users": {
            "*****@*****.**": {
                "place": 11,
                "winnings": 200
            }
        }
    }
    '''
    trmnt_data = {}
    print('hello')
    
    for index, r in df.iterrows():
        # print('r', r)
        # Get the trmnt data that's in the first row
        if index == 0:
            
            # Check trmnt existance
            trmnt = Tournaments.query.get( r['Tournament ID'] )
            print('trmnt.buy_in', trmnt.buy_in)

            if trmnt is None:
                return None, {
                    'error':'This tournament ID was not found: '+ str(r['Tournament ID'])
                }
            print('tournament', trmnt)
            trmnt.results_link = (os.environ['API_HOST'] + '/results/tournament/' + str(r['Tournament ID']) )

            # Check to see if file was uploaded already
            entry = Results.query.filter_by(
                tournament_id = r['Tournament ID']
            ).first()
            
            if entry is not None:
                return None, {
                    'error':'This tournament ID has already been uploaded: '+ str(trmnt.id)
                }
            
            # Swap Profit JSON
            trmnt_data = {
                'api_token': utils.sha256( os.environ['API_TOKEN'] ),
                'tournament_id': trmnt.id,
                'tournament_buyin': trmnt.buy_in,
                'users': {}
            }

        user_id = r['User ID'] or None
        
        # Add user to the Swap Profit JSON
        if user_id:
            user = Users.query.get( user_id )
            if user is None:
                db.session.rollback()
                return None, {
                    'error':'Couldn\'t find user with ID: '+ str(user_id)
                }
            # Swap Profit JSON
            trmnt_data['users'][user.email] = {
                'place': r['Place'],
                'winnings': r['Winnings']
                # 'user_id': user.id
            }

        # Add to PokerSociety database
        db.session.add( Results(
            tournament_id = trmnt_data['tournament_id'],
            user_id = user_id,
            full_name = r['Full Name'],
            place = r['Place'],
            nationality = r['Nationality'],
            winnings = r['Winnings']
        ))

    # If no errors, commit all data
    db.session.commit()
    # swapprofit = Subscribers.query.filter_by(company_name='Swap Profit').first()
    # if swapprofit is None:
    #     return 'Swap Profit not a subscriber'
    # resp = requests.post( 
    #         os.environ['SWAPPROFIT_API_HOST'] + '/results/update',
    #         json=trmnt_data )
    # print('resp', resp)

    return trmnt_data, {
        'message': 'Results excel processed successfully'
    }
Ejemplo n.º 8
0
def load_tournament_file():

    path = os.environ['APP_PATH']
    with open(path + '/src/jsons/tournaments.json') as f:
        data = json.load(f)

    # casino cache so not to request for same casinos
    path_cache = os.environ['APP_PATH'] + '/src/jsons/casinos.json'
    if os.path.exists(path_cache):
        with open(path_cache) as f:
            cache = json.load(f)
    else:
        cache = {}

    for r in data:

        # Do not add these to Swap Profit
        if r['Tournament'].strip() == '' or \
        'satelite' in r['Tournament'].lower() or \
        r['Results Link'] == False:
            continue

        trmnt = Tournaments.query.get(r['Tournament ID'])
        trmnt_name, flight_day = utils.resolve_name_day(r['Tournament'])
        start_at = datetime.strptime(r['Date'][:10] + r['Time'],
                                     '%Y-%m-%d%H:%M:%S')

        trmntjson = {
            'id': r['Tournament ID'],
            'name': trmnt_name,
            'start_at': start_at,
            'results_link': str(r['Results Link']).strip()
        }
        flightjson = {'start_at': start_at, 'day': flight_day}

        if trmnt is None:

            casino = cache.get(r['Casino ID'])

            trmntjson = {
                **trmntjson, 'address': casino['address'].strip(),
                'city': casino['city'].strip(),
                'state': casino['state'].strip(),
                'zip_code': str(casino['zip_code']).strip(),
                'longitude': float(casino['longitude']),
                'latitude': float(casino['latitude'])
            }

            # Create tournament
            trmnt = Tournaments(**trmntjson)
            db.session.add(trmnt)
            db.session.flush()

            # Create flight
            db.session.add(Flights(tournament_id=trmnt.id, **flightjson))

        else:
            # Create flight
            db.session.add(Flights(tournament_id=trmnt.id, **flightjson))

        db.session.commit()

    return True
Ejemplo n.º 9
0
    def get_tournaments(user_id, id):

        if id == 'all':
            now = datetime.utcnow() - timedelta(days=1)

            # Filter past tournaments
            if request.args.get('history') == 'true':
                trmnts = Tournaments.get_history()

            # Filter current and future tournaments
            else:
                trmnts = Tournaments.get_live_upcoming()

            # Filter by name
            name = request.args.get('name')
            if name is not None:
                trmnts = trmnts.filter(Tournaments.name.ilike(f'%{name}%'))

            # Order by zip code
            zip = request.args.get('zip', '')
            if zip.isnumeric():
                path = os.environ['APP_PATH']
                with open(path + '/src/zip_codes.json') as zip_file:
                    data = json.load(zip_file)
                    zipcode = data.get(zip)
                    if zipcode is None:
                        raise APIException('Zipcode not in file', 500)
                    lat = zipcode['latitude']
                    lon = zipcode['longitude']

            # Order by user location
            else:
                lat = request.args.get('lat', '')
                lon = request.args.get('lon', '')

            if isfloat(lat) and isfloat(lon):
                trmnts = trmnts.order_by(
                    (db.func.abs(float(lon) - Tournaments.longitude) +
                     db.func.abs(float(lat) - Tournaments.latitude)).asc())

            # Order by ascending date
            elif request.args.get('asc') == 'true':
                trmnts = trmnts.order_by(Tournaments.start_at.asc())

            # Order by descending date
            elif request.args.get('desc') == 'true':
                trmnts = trmnts.order_by(Tournaments.start_at.desc())

            # Pagination
            offset, limit = utils.resolve_pagination(request.args)
            trmnts = trmnts.offset(offset).limit(limit)

            return jsonify([
                actions.swap_tracker_json(trmnt, user_id) for trmnt in trmnts
            ]), 200

        # Single tournament by id
        elif id.isnumeric():
            trmnt = Tournaments.query.get(int(id))
            if trmnt is None:
                raise APIException('Tournament not found', 404)

            return jsonify(actions.swap_tracker_json(trmnt, user_id)), 200

        raise APIException('Invalid id', 400)
Ejemplo n.º 10
0
def run_seeds():


    Coins.query.delete()
    Transactions.query.delete()
    Buy_ins.query.delete()
    Swaps.query.delete()
    Flights.query.delete()
    Tournaments.query.delete()
    Profiles.query.delete()
    Users.query.delete()


    lou = Users(
        email='*****@*****.**',
        password=sha256('loustadler')
    )
    db.session.add(lou)
    lou = Profiles(
        first_name='Luiz', 
        last_name='Stadler',
        nickname='Lou',
        hendon_url='https://pokerdb.thehendonmob.com/player.php?a=r&n=207424',
        profile_pic_url='https://pokerdb.thehendonmob.com/pictures/Lou_Stadler_Winner.JPG',
        valid=True,
        user=lou
    )
    db.session.add(lou)

    cary = Users(
        email='*****@*****.**',
        password=sha256('carykatz')
    )
    db.session.add(cary)
    cary = Profiles(
        first_name='Cary', 
        last_name='Katz',
        nickname='',
        hendon_url='https://pokerdb.thehendonmob.com/player.php?a=r&n=26721',
        profile_pic_url='https://pokerdb.thehendonmob.com/pictures/carykatzpic.png',
        valid=True,
        user=cary
    )
    db.session.add(cary)

    kate = Users(
        email='*****@*****.**',
        password=sha256('kateHoang')
    )
    db.session.add(kate)
    kate = Profiles(
        first_name='Kate', 
        last_name='Hoang',
        nickname='',
        hendon_url='https://pokerdb.thehendonmob.com/player.php?a=r&n=421758',
        profile_pic_url='https://pokerdb.thehendonmob.com/pictures/Hoang_2.jpg',
        valid=True,
        user=kate
    )
    db.session.add(kate)

    nikita = Users(
        email='*****@*****.**',
        password=sha256('nikitapoker')
    )
    db.session.add(nikita)
    nikita = Profiles(
        first_name='Nikita', 
        last_name='Bodyakovskiy',
        nickname='Mikita',
        hendon_url='https://pokerdb.thehendonmob.com/player.php?a=r&n=159100',
        profile_pic_url='https://pokerdb.thehendonmob.com/pictures/NikitaBadz18FRh.jpg',
        valid=True,
        user=nikita
    )
    db.session.add(nikita)

    heartland = Tournaments(
        name='Heartland Poker Tour - HPT Colorado, Black Hawk',
        address='261 Main St, Black Hawk, CO 80422',
        start_at=datetime(2019,10,11,12),
        end_at=datetime(2019,10,11,21)
    )
    db.session.add(heartland)

    stones = Tournaments(
        name='Stones Live Fall Poker Series',
        address='6510 Antelope Rd, Citrus Heights, CA 95621',
        start_at=datetime(2019,9,30,11),
        end_at=datetime(2019,10,1,22)
    )
    db.session.add(stones)

    wpt = Tournaments(
        name='WPT DeepStacks - WPTDS Sacramento',
        address='Thunder Valley Casino Resort, 1200 Athens Ave, Lincoln, CA 95648',
        start_at=datetime(2019,10,2,12),
        end_at=datetime(2019,10,2,22)
    )
    db.session.add(wpt)

    now = datetime.utcnow()
    live = Tournaments(
        name='Live Tournament at Vegas Casino',
        address='Thunder Valley Casino Resort, 1200 Athens Ave, Lincoln, CA 95648',
        start_at=now - timedelta(days=2),
        end_at=now + timedelta(days=600)
    )
    db.session.add(live)

    flight1_live = Flights(
        start_at=now,
        end_at=now + timedelta(hours=5),
        tournament=live,
        day=1
    )
    db.session.add(flight1_live)

    flight2_live = Flights(
        start_at=now + timedelta(days=1),
        end_at=now + timedelta(days=1, hours=5),
        tournament=live,
        day=2
    )
    db.session.add(flight2_live)

    flight1_heartland = Flights(
        start_at=datetime(2019,10,11,12),
        end_at=datetime(2019,10,11,16),
        tournament=heartland,
        day=1
    )
    db.session.add(flight1_heartland)

    flight2_heartland = Flights(
        start_at=datetime(2019,10,11,16),
        end_at=datetime(2019,10,11,21),
        tournament=heartland,
        day=1
    )
    db.session.add(flight2_heartland)

    flight1_stones = Flights(
        start_at=datetime(2019,9,30,12),
        end_at=datetime(2019,9,30,15),
        tournament=stones,
        day=1
    )
    db.session.add(flight1_stones)

    flight2_stones = Flights(
        start_at=datetime(2019,9,30,15),
        end_at=datetime(2019,9,30,21),
        tournament=stones,
        day=1
    )
    db.session.add(flight2_stones)

    flight3_stones = Flights(
        start_at=datetime(2019,10,1,12),
        end_at=datetime(2019,10,1,21),
        tournament=stones,
        day=2
    )
    db.session.add(flight3_stones)

    flight1_wpt = Flights(
        start_at=datetime(2019,10,2,12),
        end_at=datetime(2019,10,2,22),
        tournament=wpt,
        day=1
    )
    db.session.add(flight1_wpt)

    db.session.add(Swaps(
        tournament=heartland,
        sender_user=lou,
        recipient_user=cary,
        percentage=10,
        winning_chips=None,
        due_at=(heartland.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=heartland,
        sender_user=cary,
        recipient_user=lou,
        percentage=10,
        winning_chips=None,
        due_at=(heartland.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=heartland,
        sender_user=nikita,
        recipient_user=kate,
        percentage=15,
        winning_chips=None,
        due_at=(heartland.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=heartland,
        sender_user=kate,
        recipient_user=nikita,
        percentage=15,
        winning_chips=None,
        due_at=(heartland.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=heartland,
        sender_user=lou,
        recipient_user=kate,
        percentage=5,
        winning_chips=None,
        due_at=(heartland.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=heartland,
        sender_user=kate,
        recipient_user=lou,
        percentage=5,
        winning_chips=None,
        due_at=(heartland.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=live,
        sender_user=lou,
        recipient_user=cary,
        percentage=10,
        winning_chips=None,
        due_at=(live.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=live,
        sender_user=cary,
        recipient_user=lou,
        percentage=10,
        winning_chips=None,
        due_at=(live.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=live,
        sender_user=nikita,
        recipient_user=kate,
        percentage=15,
        winning_chips=None,
        due_at=(live.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=live,
        sender_user=kate,
        recipient_user=nikita,
        percentage=15,
        winning_chips=None,
        due_at=(live.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=live,
        sender_user=lou,
        recipient_user=kate,
        percentage=5,
        winning_chips=None,
        due_at=(live.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=live,
        sender_user=kate,
        recipient_user=lou,
        percentage=5,
        winning_chips=None,
        due_at=(live.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=wpt,
        sender_user=lou,
        recipient_user=cary,
        percentage=10,
        winning_chips=10000,
        due_at=(wpt.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=wpt,
        sender_user=cary,
        recipient_user=lou,
        percentage=10,
        winning_chips=500,
        due_at=(wpt.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=wpt,
        sender_user=nikita,
        recipient_user=kate,
        percentage=15,
        winning_chips=100,
        due_at=(wpt.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=wpt,
        sender_user=kate,
        recipient_user=nikita,
        percentage=15,
        winning_chips=0,
        due_at=(wpt.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=wpt,
        sender_user=cary,
        recipient_user=kate,
        percentage=5,
        winning_chips=500,
        due_at=(wpt.end_at + timedelta(days=4))
    ))

    db.session.add(Swaps(
        tournament=wpt,
        sender_user=kate,
        recipient_user=cary,
        percentage=5,
        winning_chips=0,
        due_at=(wpt.end_at + timedelta(days=4))
    ))

    db.session.add(Buy_ins(
        chips=1200,
        table=1,
        seat=2,
        user=lou,
        flight=flight1_live
    ))

    db.session.add(Buy_ins(
        chips=1200,
        table=1,
        seat=4,
        user=lou,
        flight=flight1_live
    ))

    db.session.add(Buy_ins(
        chips=500,
        table=7,
        seat=1,
        user=cary,
        flight=flight1_live
    ))

    db.session.add(Buy_ins(
        chips=500,
        table=3,
        seat=2,
        user=cary,
        flight=flight2_live
    ))

    db.session.add(Buy_ins(
        chips=1000,
        table=2,
        seat=2,
        user=kate,
        flight=flight2_live
    ))

    db.session.add(Buy_ins(
        chips=300,
        table=2,
        seat=2,
        user=kate,
        flight=flight2_live
    ))
    
    db.session.add(Buy_ins(
        chips=700,
        table=3,
        seat=1,
        user=nikita,
        flight=flight2_live
    ))

    db.session.commit()
Ejemplo n.º 11
0
    def add_tournaments():

        # casino cache so not to request for same casinos
        path_cache = os.environ['APP_PATH'] + '/src/files/tournaments.json'
        if os.path.exists(path_cache):
            with open(path_cache) as f:
                cache = json.load(f)
        else:
            cache = {}

        # data comes in as a string
        data = json.loads(request.get_json())

        for r in data:

            # Do not add these to Swap Profit
            if r['Tournament'].strip() == '' or \
            'satelite' in r['Tournament'].lower() or \
            r['Results Link'] == False:
                continue

            trmnt = Tournaments.query.get(r['Tournament ID'])
            trmnt_name, flight_day = utils.resolve_name_day(r['Tournament'])
            start_at = datetime.strptime(r['Date'][:10] + r['Time'],
                                         '%Y-%m-%d%H:%M:%S')

            trmntjson = {
                'id': r['Tournament ID'],
                'name': trmnt_name,
                'start_at': start_at,
                'results_link': str(r['Results Link']).strip()
            }
            flightjson = {'start_at': start_at, 'day': flight_day}

            if trmnt is None:

                casino = cache.get(r['Casino ID'])

                if casino is None:
                    rsp = requests.get(
                        f"{os.environ['POKERSOCIETY_HOST']}/casinos/{r['Casino ID']}"
                    )
                    if not rsp.ok:
                        raise APIException(
                            f'Casino with id "{r["Casino ID"]}" not found',
                            404)

                    casino = rsp.json()
                    cache[r['Casino ID']] = casino

                trmntjson = {
                    **trmntjson, 'address': casino['address'].strip,
                    'city': casino['city'].strip,
                    'state': casino['state'].strip,
                    'zip_code': str(casino['zip_code']).strip,
                    'longitude': float(casino['longitude']),
                    'latitude': float(casino['latitude'])
                }

                # Create tournament
                trmnt = Tournaments(**trmntjson)
                db.session.add(trmnt)
                db.session.flush()

                # Create flight
                db.session.add(Flights(tournament_id=trmnt.id, **flightjson))

            else:
                # Update tournament
                for db_col, val in trmntjson.items():
                    if getattr(trmnt, db_col) != val:
                        setattr(trmnt, db_col, val)

                flight = Flights.query.filter_by( tournament_id=trmnt.id ) \
                    .filter( or_( Flights.day == flight_day, Flights.start_at == start_at )) \
                    .first()

                # Create flight
                if flight is None:
                    db.session.add(
                        Flights(tournament_id=trmnt.id, **flightjson))

                # Update flight
                else:
                    for db_col, val in flightjson.items():
                        if getattr(flight, db_col) != val:
                            setattr(flight, db_col, val)

        db.session.commit()

        # Save cache
        if cache != {}:
            with open(path_cache, 'w') as f:
                json.dump(cache, f, indent=2)

        return jsonify({'message': 'Tournaments have been updated'}), 200
Ejemplo n.º 12
0
    def update_tournaments():

        # Update from days ago or hours ago, default to 1 hour ago
        span = request.args.get('span')  # days, hours
        amount = request.args.get('amount')

        if None not in [span, amount]:
            args = f'?span={span}&amount={amount}'
        else:
            args = ''

        resp = requests.get(
            f"{os.environ['POKERSOCIETY_HOST']}/swapprofit/update{args}")
        if not resp.ok:
            raise APIException(resp.content, 500)

        data = resp.json()

        for d in data[0]:

            print('d', d)

            # CASINOS - ADD/UPDATE
            casinojson = d['casino']
            csno = Casinos.query.get(casinojson['id'])

            # CASINO Update
            if csno is None:
                print(f'Adding csno id: {casinojson["id"]}')
                db.session.add(
                    m.Casinos(**{col: val
                                 for col, val in casinojson.items()}))
            else:
                print(f'Updating csno id: {casinojson["id"]}')
                for col, val in casinojson.items():
                    if getattr(csno, col) != val:
                        setattr(csno, col, val)

        for d in data[1]:
            # TOURNAMENTS - ADD/UPDATE
            trmntjson = d['tournament']
            trmnt = Tournaments.query.get(trmntjson['id'])
            print('LISTEN', trmnt)
            x = {col: val for col, val in trmntjson.items()}
            # ADD TOURNAMENT
            if trmnt is None:
                print(f'Adding trmnt id: {trmntjson["id"]}')
                db.session.add(Tournaments(**trmntjson))

            # UPDATE TOURNAMENT
            else:
                print(f'Updating trmnt id: {trmntjson["id"]}')
                for col, val in trmntjson.items():
                    if getattr(trmnt, col) != val:
                        setattr(trmnt, col, val)

            # FLIGHTS - ADD/UPDATE
            for flightjson in d['flights']:
                flight = Flights.query.get(flightjson['id'])

                # ADD FLIGHT
                if flight is None:
                    print(f'Adding flight id: {flightjson["id"]}')
                    db.session.add(
                        Flights(
                            **{col: val
                               for col, val in flightjson.items()}))

                # UPDATE FLIGHT
                else:
                    print(f'Updating flight id: {flightjson["id"]}')
                    for col, val in flightjson.items():
                        if getattr(flight, col) != val:
                            setattr(flight, col, val)

            db.session.commit()

        return 'Tournaments updated successfully'