-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_salaries.py
39 lines (31 loc) · 1.02 KB
/
load_salaries.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
"""
Load salaries from a file and update the corresponding player record with their salary
Usage:
python load_salaries.py 3 data.json
"""
import glob
import json
import sys
from sqlalchemy import create_engine
from sqlalchemy import text
def load_salaries_for_week(week, path, year=2014):
engine = create_engine('postgresql://127.0.0.1/fantasy', echo=True)
connection = engine.connect()
with open(path, "r") as infile:
players = json.load(infile)
for player_id, player in players.iteritems():
connection.execute(text("""
UPDATE players
SET salary = :salary, fanduel_points_per_game = :fanduel
WHERE name = :name
AND year = :year
AND week = :week;
"""), **dict(
year=year,
week=week,
name=player[1],
salary=int(player[5]),
fanduel=float(player[6]),
))
if __name__=="__main__":
load_salaries_for_week(int(sys.argv[1]), sys.argv[2])