Beispiel #1
0
 def test_league_of_legends_contests(self):
     result = client.contests(Sport.LEAGUE_OF_LEGENDS)
     self.assertIsNotNone(result)
     self.assertIsNotNone(result["contests"])
     self.assertIsNotNone(result["groups"])
 "draftkings": {
     "sports":
     list(
         map((lambda sport: {
             **sport, "supported":
             sport["sportId"] in SPORT_ID_TO_PYDFS_SPORT,
             "positions":
             SPORT_ID_TO_PYDFS_SPORT[sport["sportId"]]["positions"]
             if sport["sportId"] in SPORT_ID_TO_PYDFS_SPORT else None
         }),
             sports()["sports"])),
     "contests":
     lambda sportId, sport:
     ({
         "provider": "draftkings",
         "contests": contests(sport=SPORT_ID_TO_SPORT[sportId])["contests"],
     }),
     "players":
     lambda id, gameType: ({
         "provider": "draftkings",
         "players": get_draftkings_players(id)
     }),
     "optimize":
     lambda sport, gameType: get_optimizer(
         is_captain_mode(gameType), SPORT_ID_TO_PYDFS_SPORT[sport["sportId"]
                                                            ]["sport"])
 },
 "yahoo": {
     "sports":
     list([{
         "fullName":
Beispiel #3
0
 def test_nba_contests(self):
     result = client.contests(Sport.NBA)
     self.assertIsNotNone(result)
     self.assertIsNotNone(result["contests"])
     self.assertIsNotNone(result["groups"])
Beispiel #4
0
 def test_tennis_contests(self):
     result = client.contests(Sport.TENNIS)
     self.assertIsNotNone(result)
     self.assertIsNotNone(result["contests"])
     self.assertIsNotNone(result["groups"])
Beispiel #5
0
 def test_mma_contests(self):
     result = client.contests(Sport.MIXED_MARTIAL_ARTS)
     self.assertIsNotNone(result)
     self.assertIsNotNone(result["contests"])
     self.assertIsNotNone(result["groups"])
Beispiel #6
0
 def test_eurloeage_basketball_contests(self):
     result = client.contests(Sport.EUROLEAGUE_BASKETBALL)
     self.assertIsNotNone(result)
     self.assertIsNotNone(result["contests"])
     self.assertIsNotNone(result["groups"])
Beispiel #7
0
 def test_cfl_contests(self):
     result = client.contests(Sport.CFL)
     self.assertIsNotNone(result)
     self.assertIsNotNone(result["contests"])
     self.assertIsNotNone(result["groups"])
Beispiel #8
0
 def test_college_basketball_contests(self):
     result = client.contests(Sport.COLLEGE_BASKETBALL)
     self.assertIsNotNone(result)
     self.assertIsNotNone(result["contests"])
     self.assertIsNotNone(result["groups"])
Beispiel #9
0
 def test_golf_contests(self):
     result = client.contests(Sport.GOLF)
     self.assertIsNotNone(result)
     self.assertIsNotNone(result["contests"])
     self.assertIsNotNone(result["groups"])
Beispiel #10
0
 def test_nascar_contests(self):
     result = client.contests(Sport.NASCAR)
     self.assertIsNotNone(result)
     self.assertIsNotNone(result["contests"])
     self.assertIsNotNone(result["groups"])
Beispiel #11
0
 def test_mlb_contests(self):
     result = client.contests(Sport.MLB)
     self.assertIsNotNone(result)
     self.assertIsNotNone(result["contests"])
     self.assertIsNotNone(result["groups"])
Beispiel #12
0
from draft_kings.data import Sport
from draft_kings.client import contests
from draft_kings.client import available_players
from draft_kings.client import draftables
from draft_kings.client import draft_group_details
import functools
import inspect
import os
import sys
import requests
from bs4 import BeautifulSoup
from mappings import COLUMN_MAPPINGS
from mappings import NAME_CORRECTIONS
import pandas as pd

contests_nfl = contests(sport=Sport.NFL)
contests_nba = contests(sport=Sport.NBA)
contests_mlb = contests(sport=Sport.MLB)


def get_my_path():
    try:
        filename = __file__  # where we were when the module was loaded
    except NameError:  # fallback
        filename = inspect.getsourcefile(get_my_path)
    return os.path.realpath(filename)


def changedate_nfl():
    day = datetime.datetime.now()
    while day.weekday() != 6:
Beispiel #13
0
def DKCrawler():
    dk_info = contests(sport=Sport.NBA)
    if not dk_info['contests']:
        print("Contests Empty!")
    if not dk_info['groups']:
        print("Slates Empty!")
    date = dk_info['groups'][0]['starts_at'].astimezone(
        pytz.timezone('America/Los_Angeles')).date()
    logging.info("======== DKCrawler for date %s ========" % date)
    for slate in dk_info['groups']:
        slate_date = slate['starts_at'].astimezone(
            pytz.timezone('America/Los_Angeles')).date()
        if slate_date < date:
            date = slate_date

    # Crawl contest information.
    CreateDirectoryIfNotExist(GetMetaDataPath() + '/draftkings/contests')
    contests_dict = {'CONTEST_ID': [], 'SLATE_ID' : [], 'NAME': [], 'START_TIMESTAMP': [], 'SPORT': [], 'FANTASY_PLAYER_POINTS': [], \
     'IS_GUARANTEED': [], 'IS_STARRED': [], 'IS_HEAD_TO_HEAD': [], 'IS_DOUBLE_UP': [], 'IS_FIFTY_FIFTY': [], 'TOTAL_ENTRIES': [], \
     'MAXIMUM_ENTRIES': [], 'ENTRY_FEE': [], 'TOTAL_PAYOUT': []}
    for contest in dk_info['contests']:
        if contest['sport'] is not Sport.NBA:
            continue
        contest_time = contest['starts_at'].astimezone(
            pytz.timezone('America/Los_Angeles'))
        if contest_time.date() != date:
            continue
        contests_dict['CONTEST_ID'].append(contest['id'])
        contests_dict['START_TIMESTAMP'].append(contest_time)
        contests_dict['FANTASY_PLAYER_POINTS'].append(
            contest['fantasy_player_points'])
        contests_dict['SPORT'].append(contest['sport'])
        contests_dict['NAME'].append(contest['name'])
        contests_dict['IS_GUARANTEED'].append(contest['guaranteed'])
        contests_dict['IS_STARRED'].append(contest['starred'])
        contests_dict['IS_HEAD_TO_HEAD'].append(contest['head_to_head'])
        contests_dict['IS_DOUBLE_UP'].append(contest['double_up'])
        contests_dict['IS_FIFTY_FIFTY'].append(contest['fifty_fifty'])
        contests_dict['TOTAL_ENTRIES'].append(contest['entries']['total'])
        contests_dict['MAXIMUM_ENTRIES'].append(contest['entries']['maximum'])
        contests_dict['ENTRY_FEE'].append(contest['entries']['fee'])
        contests_dict['TOTAL_PAYOUT'].append(contest['payout'])
        contests_dict['SLATE_ID'].append(contest['draft_group_id'])
    contests_df = pd.DataFrame.from_dict(contests_dict)
    contests_df.set_index('CONTEST_ID')
    contests_df.to_csv(GetMetaDataPath() + '/draftkings/contests/%s.csv' %
                       date.strftime('%Y-%m-%d'))
    logging.info("Crawl DraftKings Contests for %s, # of contests: %d" %
                 (date.strftime('%Y-%m-%d'), len(contests_df)))

    # Crawl slate information.
    CreateDirectoryIfNotExist(GetMetaDataPath() + '/draftkings/slates')
    slates_dict = {
        'SLATE_ID': [],
        'SLATE_TYPE': [],
        'START_TIMESTAMP': [],
        'SPORT': [],
        'GAMES_COUNT': []
    }
    for slate in dk_info['groups']:
        slate_time = slate['starts_at'].astimezone(
            pytz.timezone('America/Los_Angeles'))
        if slate_time.date() != date:
            continue
        slates_dict['SLATE_ID'].append(slate['id'])
        slates_dict['SLATE_TYPE'].append(
            DRAFTKINGS_SLATE_TYPE[slate['contest_type_id']])
        slates_dict['START_TIMESTAMP'].append(slate_time)
        slates_dict['SPORT'].append(slate['sport'])
        slates_dict['GAMES_COUNT'].append(slate['games_count'])
    slates_df = pd.DataFrame.from_dict(slates_dict)
    slates_df.set_index('SLATE_ID')
    slates_df.to_csv(GetMetaDataPath() +
                     '/draftkings/slates/%s.csv' % date.strftime('%Y-%m-%d'))
    logging.info("Crawl DraftKings Slates for %s" % date.strftime('%Y-%m-%d'))
    print(slates_df)

    # Crawl player information
    CreateDirectoryIfNotExist(GetMetaDataPath() + '/draftkings/players')
    players_dict = {
        'NAME': [],
        'DK_ID': [],
        'POSITION': [],
        'SALARY': [],
        'SLATE_ID': [],
        'GAME_INFO': [],
        'TEAM': [],
        'DKP': []
    }
    for slate_id in slates_dict['SLATE_ID']:
        lines = urlopen(GetDKPlayersForSlateUrl(slate_id))

        # Header contains lineup position
        header = next(lines).decode("utf-8")
        start_column = 0
        end_column = header.index('Instructions') - 2
        lineup_positions = header[start_column:end_column].split(',')

        # Go through instruction lines
        while True:
            line = next(lines).decode("utf-8")
            if "Position" in line:
                start_column = line.index("Position")
                break

        # Parse players data
        for line in lines:
            # POST data is in bytes
            line = line.decode("utf-8")
            fields = line[start_column:].split(',')
            # For tier slate, set salary as 1
            if len(fields) == 8:
                fields.insert(5, 1)
            players_dict['NAME'].append(fields[2])
            players_dict['DK_ID'].append(fields[3])
            players_dict['POSITION'].append(fields[0])
            players_dict['SALARY'].append(fields[5])
            players_dict['SLATE_ID'].append(slate_id)
            players_dict['GAME_INFO'].append(fields[6])
            players_dict['TEAM'].append(fields[7])
            players_dict['DKP'].append(fields[8])
    players_df = pd.DataFrame.from_dict(players_dict)
    players_df.set_index('NAME')
    players_df.to_csv(GetMetaDataPath() +
                      '/draftkings/players/%s.csv' % date.strftime('%Y-%m-%d'))
    logging.info("Crawl DraftKings Players for %s" % date.strftime('%Y-%m-%d'))