示例#1
0
def main():
    drive = Drive()

    league = _league_stats(drive)

    for team in league.keys():
        _upload_stats(team, league[team])
示例#2
0
    def _fetch_spreadsheet(self, week):
        data = None
        drive = Drive()
        index = 0
        margin = {}
        odds = 0
        over_under = ''
        result = {}
        selections = {}
        spread = {}
        spreadsheet = ''
        tagline = self._get_tagline(week)
        target = ''
        team_name = ''
        total_score = 0
        worksheet = constants.DEFAULT_WORKSHEET
        
        data_sheets = drive.list_spreadsheets()
        try:
            index = data_sheets.index(tagline)
            spreadsheet = data_sheets[index]
        except ValueError:
            # No data sheet currently available
            logging.warning('Failed to load data sheet:  ' + spreadsheet +
                    '(' + worksheet + ')')
            spreadsheet = ''

        data = drive.get_data(spreadsheet, worksheet)
        if len(data) > 0:
            # START: Get each individual's spread choices
            for i in data:
                current = data[i]
                header = current[0]

                # Skip the labels
                if 'GAME' in header or 'WEEK' in header:
                    continue

                # Clear local values
                flush = False
                over_under = ''
                selections[header] = []
                team_name = ''
                total_score = ''

                # 1-->offset; 3-->season-long information
                for picks in current[1+3:]:
                    # No team name; fresh start
                    if len(team_name) == 0:
                        team_name = picks
                    # Team name set, but not over/under
                    elif len(over_under) == 0:
                        # Check if over...
                        if picks == 'OV':
                            over_under = picks
                        # ...check if under...
                        elif picks == 'UN':
                            over_under = picks
                        # ...it's anoter team
                        else:
                            over_under = '0'
                            total_score = '0'
                            flush = True
                    # Team name & over/under set, but not total score
                    elif len(total_score) == 0:
                        try:
                            total_score = str(int(picks))
                        except ValueError:
                            # It's not a number...
                            total_score = '0'

                        flush = True

                    if flush:
                        # Save data
                        selections[header].append([
                            team_name,
                            over_under,
                            total_score
                            ])

                        # Reset
                        if total_score == '0':
                            # Flushed early if total_score is 0
                            team_name = picks
                        else:
                            team_name = ''
                        over_under = ''
                        total_score = ''
                        flush = False
            # END: Get each individual's spread choices

        result = selections
        return result
示例#3
0
    def get(self):
        drive = Drive()
        margin = {}
        odds = 0
        result = {}
        selections = {}
        spread = {}
        spreadsheet = self.request.get('spreadsheet_name')
        worksheet = self.request.get('worksheet_name')

        # Default values
        if spreadsheet is None or len(spreadsheet) == 0:
            spreadsheet = (drive.list_spreadsheets())[0]
        if worksheet is None or len(worksheet) == 0:
            worksheet = 'Sheet1'

        data = drive.get_data(spreadsheet, worksheet)
        # Get each individual's spread choices
        for i in data:
            current = data[i]
            header = current[0]

            # Skip the labels
            if 'GAME' in header or 'WEEK' in header:
                continue

            # 1: offset. 3: season-long information
            selections[header] = current[1+3:]

        # Parse for spread data
        last_team = ''
        for team in data[2][5:]:
            # Skip day-name labels
            if 'DAY' in team:
                continue
            # Save the over/under margin
            if 'OVER' in team:
                index = team.index(' ')

                over_under = int(team[index:-3])
                over_under = (over_under + 0.5)
                
                margin[last_team] = over_under
                
                continue
            # Skip total points tally
            if 'TOTAL' in team:
                continue

            # Detect for underdog
            if team[0] == '_':
                spread[team[1:].upper()] = (odds * -1)
            else:
                #Format is: "TEAMNAME-12345 1/2"
                deliminator = team.index('-')

                odds = int(team[deliminator:-3])
                odds = (odds - 0.5)
                
                last_team = team[:deliminator].upper()
                
                spread[last_team] = odds

        # Format the result
        result['spread'] = selections
        result['odds'] = spread
        result['margin'] = margin

        self.response.headers['Content-Type'] = 'application/json'
        self.response.headers['Access-Control-Allow-Origin'] = '*'
        self.response.out.write(json.dumps(result, indent = 4))      
示例#4
0
    def _fetch_spread(self, spreadsheet, worksheet):
        current_season = 'S' + str(self.get_season_year())
        current_week = self.get_current_week()
        data_sheets = []
        drive = Drive()
        index = 0
        margin = {}
        odds = 0
        result = {}
        selections = {}
        spread = {}
        target = ''

        # Default values
        if spreadsheet is None or len(spreadsheet) == 0:
            if current_week < 10:
                target = 'W0' + str(current_week)
            else:
                target = 'W' + str(current_week)

            data_sheets = drive.list_spreadsheets()
            try:
                index = data_sheets.index(current_season + target)
                spreadsheet = data_sheets[index]
            except ValueError:
                # No data sheet currently available
                spreadsheet = ''
        if worksheet is None or len(worksheet) == 0:
            worksheet = 'Sheet1'

        data = drive.get_data(spreadsheet, worksheet)
        # Get each individual's spread choices
        if len(data) > 0:
            for i in data:
                current = data[i]
                header = current[0]

                # Skip the labels
                if 'GAME' in header or 'WEEK' in header:
                    continue

                # 1: offset. 3: season-long information
                selections[header] = current[1 + 3:]

            # Parse for spread data
            last_team = ''
            over_under = 0
            for team in data[2][5:]:
                # Skip day-name labels
                if 'DAY' in team:
                    continue
                # Save the over/under margin
                if 'OVER' in team:
                    index = team.index(' ')

                    over_under = int(team[index:-3])
                    over_under = (over_under + 0.5)

                    margin[last_team] = over_under

                    continue
                # Skip total points tally
                if 'TOTAL' in team:
                    continue

                # Detect for underdog
                if team[0] == '_':
                    spread[team[1:].upper()] = (odds * -1)
                else:
                    #Format is: "TEAMNAME-12345 1/2"
                    deliminator = team.index('-')

                    odds = int(team[deliminator:-3])
                    odds = (odds - 0.5)

                    last_team = team[:deliminator].upper()

                    spread[last_team] = odds

        # Format the result
        result['spread'] = selections
        result['odds'] = spread
        result['margin'] = margin

        return result
示例#5
0
    def _fetch_spread(self, spreadsheet, worksheet):
        current_season = 'S' + str(self.get_season_year())
        current_week = self.get_current_week()
        data_sheets = []
        drive = Drive()
        index = 0
        margin = {}
        odds = 0
        result = {}
        selections = {}
        spread = {}
        target = ''

        # Default values
        if spreadsheet is None or len(spreadsheet) == 0:
            if current_week < 10:
                target = 'W0' + str(current_week)
            else:
                target = 'W' + str(current_week)

            data_sheets = drive.list_spreadsheets()
            try:
                index = data_sheets.index(current_season + target)
                spreadsheet = data_sheets[index]
            except ValueError:
                # No data sheet currently available
                spreadsheet = ''
        if worksheet is None or len(worksheet) == 0:
            worksheet = 'Sheet1'

        data = drive.get_data(spreadsheet, worksheet)
        # Get each individual's spread choices
        if len(data) > 0:
            for i in data:
                current = data[i]
                header = current[0]

                # Skip the labels
                if 'GAME' in header or 'WEEK' in header:
                    continue

                # 1: offset. 3: season-long information
                selections[header] = current[1+3:]

            # Parse for spread data
            last_team = ''
            over_under = 0
            for team in data[2][5:]:
                # Skip day-name labels
                if 'DAY' in team:
                    continue
                # Save the over/under margin
                if 'OVER' in team:
                    index = team.index(' ')

                    over_under = int(team[index:-3])
                    over_under = (over_under + 0.5)
                
                    margin[last_team] = over_under
                
                    continue
                # Skip total points tally
                if 'TOTAL' in team:
                    continue

                # Detect for underdog
                if team[0] == '_':
                    spread[team[1:].upper()] = (odds * -1)
                else:
                    #Format is: "TEAMNAME-12345 1/2"
                    deliminator = team.index('-')

                    odds = int(team[deliminator:-3])
                    odds = (odds - 0.5)
                
                    last_team = team[:deliminator].upper()
                
                    spread[last_team] = odds

        # Format the result
        result['spread'] = selections
        result['odds'] = spread
        result['margin'] = margin
        
        return result
示例#6
0
    def _fetch_odds(self, week):
        data = {}
        drive = Drive()
        margin = {}
        odds = 0
        result = {}
        spread = {}
        spreadsheet = ''
        target = ''
        worksheet = constants.DEFAULT_WORKSHEET

        # Obtain the correct spread sheet
        data_sheets = drive.list_spreadsheets()
        try:
            if week < 10:
                target = 'W0' + str(week)
            else:
                target = 'W' + str(week)
            index = data_sheets.index('S' + str(constants.YEAR) + target)
            spreadsheet = data_sheets[index]
        except ValueError:
            #No data sheet currently available
            logging.warning('Failed to load data sheet:  ' + spreadsheet)
            spreadsheet = ''

        data = drive.get_data(spreadsheet, worksheet)
        if len(data) > 0:
            last_team = ''
            over_under = 0
            for team in data[2][5:]:
                # Skip day-name labels
                if 'DAY' in team:
                    continue
                # Save the over/under margin
                if 'OVER' in team:
                    index = team.index(' ')
                
                    over_under = int(team[index:-3])
                    over_under = (over_under + 0.5)
                    
                    margin[last_team] = over_under
                
                    continue
                # Skip total-game-points tally
                if 'TOTAL' in team:
                    continue

                # Detect for underdog
                if team[0] == '_':
                    last_team = constants.TEAM_NAME[team[1:].upper()]
                    spread[last_team] = (odds * -1)
                else:
                    # Format is: "TEAMNAME-12345 1/2"
                    deliminator = team.index('-')
                    
                    odds = int(team[deliminator:-3])
                    odds = (odds - 0.5)
                  
                    last_team = constants.TEAM_NAME[team[:deliminator].upper()]
                
                    spread[last_team] = odds

        result['odds'] = spread
        result['margin'] = margin
        return result
示例#7
0
    def get(self):
        drive = Drive()
        margin = {}
        odds = 0
        result = {}
        selections = {}
        spread = {}
        spreadsheet = self.request.get('spreadsheet_name')
        worksheet = self.request.get('worksheet_name')

        # Default values
        if spreadsheet is None or len(spreadsheet) == 0:
            spreadsheet = (drive.list_spreadsheets())[0]
        if worksheet is None or len(worksheet) == 0:
            worksheet = 'Sheet1'

        data = drive.get_data(spreadsheet, worksheet)
        # Get each individual's spread choices
        for i in data:
            current = data[i]
            header = current[0]

            # Skip the labels
            if 'GAME' in header or 'WEEK' in header:
                continue

            # 1: offset. 3: season-long information
            selections[header] = current[1 + 3:]

        # Parse for spread data
        last_team = ''
        for team in data[2][5:]:
            # Skip day-name labels
            if 'DAY' in team:
                continue
            # Save the over/under margin
            if 'OVER' in team:
                index = team.index(' ')

                over_under = int(team[index:-3])
                over_under = (over_under + 0.5)

                margin[last_team] = over_under

                continue
            # Skip total points tally
            if 'TOTAL' in team:
                continue

            # Detect for underdog
            if team[0] == '_':
                spread[team[1:].upper()] = (odds * -1)
            else:
                #Format is: "TEAMNAME-12345 1/2"
                deliminator = team.index('-')

                odds = int(team[deliminator:-3])
                odds = (odds - 0.5)

                last_team = team[:deliminator].upper()

                spread[last_team] = odds

        # Format the result
        result['spread'] = selections
        result['odds'] = spread
        result['margin'] = margin

        self.response.headers['Content-Type'] = 'application/json'
        self.response.headers['Access-Control-Allow-Origin'] = '*'
        self.response.out.write(json.dumps(result, indent=4))
示例#8
0
    def _fetch_odds(self, week):
        data = {}
        drive = Drive()
        margin = {}
        odds = 0
        result = {}
        spread = {}
        spreadsheet = ''
        target = ''
        worksheet = constants.DEFAULT_WORKSHEET

        # Obtain the correct spread sheet
        data_sheets = drive.list_spreadsheets()
        try:
            if week < 10:
                target = 'W0' + str(week)
            else:
                target = 'W' + str(week)
            index = data_sheets.index('S' + str(constants.YEAR) + target)
            spreadsheet = data_sheets[index]
        except ValueError:
            #No data sheet currently available
            logging.warning('Failed to load data sheet:  ' + spreadsheet)
            spreadsheet = ''

        data = drive.get_data(spreadsheet, worksheet)
        if len(data) > 0:
            last_team = ''
            over_under = 0
            for team in data[2][5:]:
                # Skip day-name labels
                if 'DAY' in team:
                    continue
                # Save the over/under margin
                if 'OVER' in team:
                    index = team.index(' ')

                    over_under = int(team[index:-3])
                    over_under = (over_under + 0.5)

                    margin[last_team] = over_under

                    continue
                # Skip total-game-points tally
                if 'TOTAL' in team:
                    continue

                # Detect for underdog
                if team[0] == '_':
                    last_team = constants.TEAM_NAME[team[1:].upper()]
                    spread[last_team] = (odds * -1)
                else:
                    # Format is: "TEAMNAME-12345 1/2"
                    deliminator = team.index('-')

                    odds = int(team[deliminator:-3])
                    odds = (odds - 0.5)

                    last_team = constants.TEAM_NAME[team[:deliminator].upper()]

                    spread[last_team] = odds

        result['odds'] = spread
        result['margin'] = margin
        return result