Пример #1
0
    def findTeamById(self):
        connection = None

        try:
            print('findTeamById: ' + str(self.id))
            if self.id is not None:
                connection = connection_settings.createConnection()

                with connection.cursor() as cursor:

                    cursor.execute(self.find_by_id, (self.id))
                    result = cursor.fetchone()
                    print(result)
                    if result == None:
                        raise RuntimeError(
                            'Error in findTeamById: \'results\' == None for TEAM_ID:  '
                            + self.id)
                    self.createTeamFromResults(result)

        except Exception as e:
            print('Error in findTeamById: ' + str(e))
            pass
        finally:
            if connection is not None:
                connection.close()
Пример #2
0
    def findScheduleByDateTeams(self):

        try:
            
            if self.game_date != None \
            and self.home_team != None \
            and self.away_team != None:
            
                connection = connection_settings.createConnection();

                with connection.cursor() as cursor:
                    cursor.execute(self.find_schedule_date_teams,(self.game_date, self.home_team.id, self.away_team.id))
                    result = cursor.fetchone()
                    if result == None:
                        raise RuntimeError('Error in findScheduleByDateTeams: \'results\' == None for HOME_TEAM_ID: ' + str(self.home_team.id) + '. AWAY_TEAM_ID: ' + str(self.away_team.id) + '. GAME_DATE: ' + datetime.datetime.strftime(self.game_date, '%Y/%m/%d'))
                    
                    print('game updated for schedule table: ' + self.away_team.schedule_name + ' @ ' + self.home_team.schedule_name + ' ' + datetime.datetime.strftime(self.game_date, '%Y/%m/%d'))

            
            
        except Exception as e:
            print('Issue in findScheduleByDateTeams: \n' + str(e) + '\n' + 'home team schedule name: ' + self.home_team.schedule_name)
        finally:
            if connection is not None:
                connection.close()
Пример #3
0
def getPicks(date):

    try:
        connection = connection_settings.createConnection()

        with connection.cursor() as cursor:
            cursor.execute(pick_query, (date))
            picks = cursor.fetchall()
            print(picks)
            return picks
    except Exception as e:
        print(str(e))
Пример #4
0
    def insertSchedule(self):
    
        try:
            if self.game_date != None \
            and self.game_time != None \
            and self.home_team != None \
            and self.away_team != None:
               connection = connection_settings.createConnection();

               with connection.cursor() as cursor:
                   cursor.execute(self.insert_initial_schedule_sql,(self.game_date, self.game_time,self.home_team.id, self.away_team.id) )
                   connection.commit()
                   print('game inserted into schedule table: ' + self.away_team.schedule_name + ' @ ' + self.home_team.schedule_name + ' ' + datetime.datetime.strftime(self.game_date, '%Y/%m/%d') + ' ' + datetime.time.strftime(self.game_time,'%H:%M')  )
                   connection.close()
        
        except Exception as e:
            print('Issue in insertSchedule: \n' + str(e) + '\n' + 'home team schedule name: ' + self.home_team.schedule_name)
Пример #5
0
    def updateTeam(self):
        try:
            if self.id is not 0 and self.spread_name is not '' and self.schedule_name is not '':

                connection = connection_settings.createConnection()

                with connection.cursor() as cursor:

                    cursor.execute(
                        self.update_team_query,
                        (self.spread_name, self.schedule_name, self.wins,
                         self.losses, self.ats_wins, self.ats_losses, self.id))
                    connection.commit()

        except Exception as e:
            print('Error in findTeamBySpreadName: ' + str(e))
            pass
        finally:
            connection.close()
Пример #6
0
    def getPicksByDate(self, date):
        connectio = None
        picks = []
        try:
            print(date)
            connection = connection_settings.createConnection()
            if connection is not None and date is not None:

                with connection.cursor() as cursor:

                    cursor.execute(self.select_picks_by_date, (date))
                    results = cursor.fetchall()

                    return results

        except Exception as e:
            print('Issue in getPicksByDate(): ' + str(e))
        finally:
            if connection is not None:
                connection.close()
Пример #7
0
    def updatePick(self):
        try:
            connection = connection_settings.createConnection()
            if connection is not None and self.game_date is not None \
            and self.home_team is not None \
            and self.away_team is not None:

                with connection.cursor() as cursor:

                    cursor.execute(self.update_pick_by_id,
                                   (self.picked_correctly, self.pick_id))
                    connection.commit()

                    print('Update pick complete... picked correctly: ' +
                          self.favorite_team.spread_name)

        except Exception as e:
            print('Issue in updatePick(): ' + str(e))
        finally:
            connection.close()
Пример #8
0
    def insertTeam(self):
        try:
            if ((self.spread_name is not None and self.spread_name is not '')
                    and (self.schedule_name is not None
                         and self.schedule_name is not '')):

                connection = connection_settings.createConnection()

                with connection.cursor() as cursor:

                    cursor.execute(
                        self.insert_team_query,
                        (self.spread_name, self.schedule_name, self.wins,
                         self.losses, self.ats_wins, self.ats_losses, self.id))
                    connection.commit()
        except Exception as e:
            print('Issue in insertTeam: ' + str(e))
            pass
        finally:
            connection.close()
Пример #9
0
    def selectPick(self):
        try:
            connection = connection_settings.createConnection()
            if connection is not None and self.game_date is not None \
            and self.home_team is not None \
            and self.away_team is not None:

                with connection.cursor() as cursor:

                    cursor.execute(
                        self.select_pick_by_date_home_away,
                        (self.game_date, self.home_team.id, self.away_team.id))
                    connection.commit()

                    print('Select pick complete: date: ' + datetime.datetime.strftime(self.game_date,'%Y/%m/%d') + ' time: ' + datetime.time.strftime(self.game_time, '%H:%M') + '. Home team: ' \
                    + self.home_team.spread_name + '. Spread: ' + str(self.spread) +'. Away team: ' + self.away_team.spread_name + 'Favorite team: ' + self.favorite_team.spread_name )

        except Exception as e:
            print('Issue in selectPick(): ' + str(e))
        finally:
            connection.close()
Пример #10
0
    def updateSchedule(self):
        
        try:
            
            if self.game_date != None \
            and self.home_team != None \
            and self.away_team != None:
               
                connection = connection_settings.createConnection();

                with connection.cursor() as cursor:
                    
                    cursor.execute(self.update_schedule_sql,(self.home_team_score, self.away_team_score, self.winning_team.id, self.losing_team.id, self.home_team.id, self.away_team.id, self.game_date.date()) )
                    connection.commit()
                    print(cursor._last_executed)
                    #print('game updated for schedule table: ' + self.away_team.schedule_name + ' @ ' + self.home_team.schedule_name + ' ' + datetime.datetime.strftime(self.game_date, '%Y/%m/%d')  + str(self.winning_team.id) + str(self.losing_team.id) )
                    connection.close()
            
            
        except Exception as e:
            print('Issue in updateSchedule: \n' + str(e) + '\n' + 'home team schedule name: ' + self.home_team.schedule_name)
Пример #11
0
    def findTeamBySpreadName(self):

        if self.spread_name is not '':

            try:
                connection = connection_settings.createConnection()

                with connection.cursor() as cursor:

                    cursor.execute(self.find_by_spread_query,
                                   (self.spread_name))
                    result = cursor.fetchone()
                    if result == None:
                        raise RuntimeError(
                            'Error in findTeamBySpreadName: \'results\' == None for '
                            + self.spread_name)
                    self.createTeamFromResults(result)
            except Exception as e:
                print('Error in findTeamBySpreadName: ' + str(e))
                pass
            finally:
                connection.close()
Пример #12
0
    def insertPick(self):
        insert_pick_query = 'INSERT PICK (GAME_DATE, GAME_TIME, HOME_TEAM_ID, SPREAD, AWAY_TEAM_ID, FAVORITE_TEAM_ID) VALUES (%s, %s, %s, %s, %s, %s)'
        try:
            connection = connection_settings.createConnection()

            if connection is not None and self.game_date is not None \
            and self.game_time is not None and self.home_team is not None \
            and self.away_team is not None and self.favorite_team is not None:

                with connection.cursor() as cursor:

                    cursor.execute(insert_pick_query,
                                   (self.game_date, self.game_time,
                                    self.home_team.id, self.spread,
                                    self.away_team.id, self.favorite_team.id))
                    connection.commit()

                    print('Insert into pick complete: date: ' + datetime.datetime.strftime(self.game_date,'%Y/%m/%d') + '. Home team: ' \
                    + self.home_team.spread_name + '. Away team: ' + self.away_team.spread_name )

        except Exception as e:
            print('Issue in insertPick(): ' + str(e))
        finally:
            connection.close()
Пример #13
0
    def findTeamByScheduleName(self):
        try:
            if self.schedule_name is not '':

                #TODO - Check if team is in DB.
                connection = connection_settings.createConnection()

                with connection.cursor() as cursor:

                    cursor.execute(self.find_by_schedule_query,
                                   (self.schedule_name))
                    result = cursor.fetchone()
                    if result == None:
                        raise RuntimeError(
                            'Error in findTeamByScheduleName: \'results\' == None for '
                            + self.schedule_name)

                    self.createTeamFromResults(result)
                    self.printTeam()
        except Exception as e:
            print('Issue in findTeamByScheduleName: ' + str(e))
            pass
        finally:
            connection.close()
Пример #14
0
def main():
    connection = conn.createConnection()
    db_Info = connection.get_server_info()
    print("Connected to MySQL database... MySQL Server version on ", db_Info)