# Path: nflpool/data/dbsession.py
# class DbSessionFactory:
#     factory = None
# 
#     # Start a database session at app startup
#     @staticmethod
#     def global_init(db_file):
#         if DbSessionFactory.factory:
#             return
# 
#         if not db_file or not db_file.strip():
#             raise Exception("You must specify a data file.")
# 
#         conn_str = "sqlite:///" + db_file
#         print("Connecting to db with conn string: {}".format(conn_str))
# 
#         engine = sqlalchemy.create_engine(conn_str, echo=False)
# 
#         SqlAlchemyBase.metadata.create_all(engine)
#         DbSessionFactory.factory = sqlalchemy.orm.sessionmaker(bind=engine)
# 
#     @staticmethod
#     def create_session():
#         return DbSessionFactory.factory()
# 
# Path: nflpool/data/nflschedule.py
# class NFLSchedule(SqlAlchemyBase):
#     __tablename__ = "NFLSchedule"
#     game_id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
#     game_date = sqlalchemy.Column(sqlalchemy.DateTime, index=True)
#     away_team = sqlalchemy.Column(sqlalchemy.Integer)
#     home_team = sqlalchemy.Column(sqlalchemy.Integer)
#     week = sqlalchemy.Column(sqlalchemy.Integer, index=True)
#     season = sqlalchemy.Column(sqlalchemy.Integer)
# 
# Path: nflpool/data/seasoninfo.py
# class SeasonInfo(SqlAlchemyBase):
#     __tablename__ = "SeasonInfo"
#     id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True, autoincrement=True)
#     current_season = sqlalchemy.Column(sqlalchemy.Integer)
#     season_start_date = sqlalchemy.Column(sqlalchemy.String)
#     home_team = sqlalchemy.Column(sqlalchemy.String)
#     away_team = sqlalchemy.Column(sqlalchemy.String)


import requests
import nflpool.data.secret as secret
import pendulum
from nflpool.data.dbsession import DbSessionFactory
from nflpool.data.nflschedule import NFLSchedule
from requests.auth import HTTPBasicAuth
from nflpool.data.seasoninfo import SeasonInfo
        session = DbSessionFactory.create_session()

        season_row = session.query(SeasonInfo).filter(SeasonInfo.id == "1").first()
        season = season_row.current_season

        response = requests.get(
            "https://api.mysportsfeeds.com/v2.0/pull/nfl/"
            + str(season)
            + "-regular/games.json",
            auth=HTTPBasicAuth(secret.msf_api, secret.msf_v2pw),
        )

        schedule_query = response.json()
        team_schedule = schedule_query["games"]
        print(type(team_schedule), team_schedule)

        x = 0

        for schedule in team_schedule:

            game_id = team_schedule[x]["schedule"]["id"]
            week = team_schedule[x]["schedule"]["week"]
            game_time = team_schedule[x]["schedule"]["startTime"]
            away_team = team_schedule[x]["schedule"]["awayTeam"]["id"]
            home_team = team_schedule[x]["schedule"]["homeTeam"]["id"]

            game_date = pendulum.parse(game_time)

            x = x + 1


# Path: nflpool/data/dbsession.py
# class DbSessionFactory:
#     factory = None
# 
#     # Start a database session at app startup
#     @staticmethod
#     def global_init(db_file):
#         if DbSessionFactory.factory:
#             return
# 
#         if not db_file or not db_file.strip():
#             raise Exception("You must specify a data file.")
# 
#         conn_str = "sqlite:///" + db_file
#         print("Connecting to db with conn string: {}".format(conn_str))
# 
#         engine = sqlalchemy.create_engine(conn_str, echo=False)
# 
#         SqlAlchemyBase.metadata.create_all(engine)
#         DbSessionFactory.factory = sqlalchemy.orm.sessionmaker(bind=engine)
# 
#     @staticmethod
#     def create_session():
#         return DbSessionFactory.factory()
# 
# Path: nflpool/data/nflschedule.py
# class NFLSchedule(SqlAlchemyBase):
#     __tablename__ = "NFLSchedule"
#     game_id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
#     game_date = sqlalchemy.Column(sqlalchemy.DateTime, index=True)
#     away_team = sqlalchemy.Column(sqlalchemy.Integer)
#     home_team = sqlalchemy.Column(sqlalchemy.Integer)
#     week = sqlalchemy.Column(sqlalchemy.Integer, index=True)
#     season = sqlalchemy.Column(sqlalchemy.Integer)
# 
# Path: nflpool/data/seasoninfo.py
# class SeasonInfo(SqlAlchemyBase):
#     __tablename__ = "SeasonInfo"
#     id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True, autoincrement=True)
#     current_season = sqlalchemy.Column(sqlalchemy.Integer)
#     season_start_date = sqlalchemy.Column(sqlalchemy.String)
#     home_team = sqlalchemy.Column(sqlalchemy.String)
#     away_team = sqlalchemy.Column(sqlalchemy.String)


# Path: nflpool/services/update_nflschedule_service.py
import requests
import nflpool.data.secret as secret
import pendulum
from nflpool.data.dbsession import DbSessionFactory
from nflpool.data.nflschedule import NFLSchedule
from requests.auth import HTTPBasicAuth
from nflpool.data.seasoninfo import SeasonInfo

        session = DbSessionFactory.create_session()

        season_row = session.query(SeasonInfo).filter(SeasonInfo.id == "1").first()
        season = season_row.current_season

        response = requests.get(
            "https://api.mysportsfeeds.com/v2.0/pull/nfl/"
            + str(season)
            + "-regular/games.json",
            auth=HTTPBasicAuth(secret.msf_api, secret.msf_v2pw),
        )

        schedule_query = response.json()
        team_schedule = schedule_query["games"]
        print(type(team_schedule), team_schedule)

        x = 0

        for schedule in team_schedule:

            game_id = team_schedule[x]["schedule"]["id"]
            week = team_schedule[x]["schedule"]["week"]
            game_time = team_schedule[x]["schedule"]["startTime"]
            away_team = team_schedule[x]["schedule"]["awayTeam"]["id"]
            home_team = team_schedule[x]["schedule"]["homeTeam"]["id"]

            game_date = pendulum.parse(game_time)

            x = x + 1


            season_row = session.query(SeasonInfo).filter(SeasonInfo.id == "1").first()