-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_projections.py
62 lines (53 loc) · 1.64 KB
/
load_projections.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import glob
import json
import sys
from sqlalchemy import create_engine
from sqlalchemy import text
PATHS = [
"QB_{}.data",
"DEF_{}.data",
"K_{}.data",
"RB_{}.data",
"TE_{}.data",
"WR_{}.data",
]
engine = create_engine('postgresql://127.0.0.1/fantasy', echo=True)
connection = engine.connect()
week = int(sys.argv[1])
assert 1 <= week <= 17
connection.execute(text("delete from players where week = :week"), week=week)
for pattern in PATHS:
path = pattern.format(week)
print path
with open(path, "r") as infile:
data = json.load(infile)
year = 2014
week = data['Week']
players = data['Rankings']
for player in players:
connection.execute(text("""
INSERT INTO players
(name, team, position, year, week,
standard, standard_low, standard_high,
ppr, ppr_low, ppr_high,
injury, practice_status, game_status)
VALUES (:name, :team, :position, :year, :week,
:standard, :standard_low, :standard_high,
:ppr, :ppr_low, :ppr_high,
:injury, :practice_status, :game_status)
"""), **dict(
name=player['name'],
team=player['team'],
position=player['position'],
year=year,
week=week,
standard=player['standard'],
standard_low=player['standardLow'],
standard_high=player['standardHigh'],
ppr=player['ppr'],
ppr_low=player['pprLow'],
ppr_high=player['pprHigh'],
injury=player['injury'],
practice_status=player['practiceStatus'],
game_status=player['gameStatus']
))