# -*- coding: utf-8 -*-
# Generated by Django 1.10.2 on 2016-10-27 01:42
from __future__ import unicode_literals

from django.db import migrations

import csv

def add_info(apps, schema_editor):
    Master = apps.get_model("baseball_api_app", "Master")
    Batting = apps.get_model("baseball_api_app", "Batting")
    Pitching = apps.get_model("baseball_api_app", "Pitching")
    Fielding = apps.get_model("baseball_api_app", "Fielding")


    with open("fielding.csv") as open_file:
        fielding_info = csv.DictReader(open_file)
        for row in fielding_info:
            player_code = Master.objects.get(player_code=row["playerID"])
            Fielding.objects.create(player_code=player_code,year_code=row["yearID"],stint=row["stint"],team_code=row["teamID"],
                                   league_code=row["lgID"],position=row["POS"],games=row["G"],games_started=row["GS"],inn_outs=row["InnOuts"],
                                   putouts=row["PO"],assists=row["A"],errors=row["E"],double_plays=row["DP"],
                                   passed_balls=row["PB"],wild_pitches=row["WP"],opp_stolen_bases=row["SB"],opp_caught_stealing=row["CS"],
                                   zone_rating=row["ZR"]
                                   )



class Migration(migrations.Migration):

    dependencies = [
        ('baseball_api_app', '0007_auto_20161027_0044'),
    ]

    operations = [
                migrations.RunPython(add_info)
    ]
