-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
37 lines (31 loc) · 1.09 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import string
from functools import partial
from itertools import combinations
from multiprocessing import Pool
from tqdm import tqdm
from app import db
from ingest import GamelogIngester, HeadtoheadIngester, PlayerIngester
from utils import find_player_code
def _get_items(ingester, option):
"""Call find on a given class."""
ingester(option).find()
def create(collection):
"""Create a collection in the nba database."""
if collection == 'gamelogs':
options = (
url
for player in db.players.find()
for url in player['GamelogURLs']
)
ingester = GamelogIngester
elif collection == 'headtoheads':
options = combinations((find_player_code(player['Player'])
for player in db.players.find()), 2)
ingester = HeadtoheadIngester
elif collection == 'players':
options = string.ascii_lowercase
ingester = PlayerIngester
else:
raise NotImplementedError('Not a supported collection type.')
for option in tqdm(options):
_get_items(ingester, option)