# 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/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()


from nflpool.data.seasoninfo import SeasonInfo
from nflpool.data.dbsession import DbSessionFactory
from requests.auth import HTTPBasicAuth
import requests
import pendulum
import nflpool.data.secret as secret

            new_season = SeasonInfo(
                season_start_date=first_game_date,
                home_team=home_team,
                away_team=away_team,
                current_season=season,
            )

            session.add(new_season)
            session.commit()

        else:
            print("Existing season found, updating to new year")

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

            gameday_json = response.json()
            gameday_data = gameday_json["games"][0]

            first_game_date = gameday_data["startTime"]
            home_team = gameday_data["homeTeam"]["id"]
            away_team = gameday_data["awayTeam"]["id"]

            first_game_calc = pendulum.parse(first_game_date)


# 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/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/services/new_season_service.py
from nflpool.data.seasoninfo import SeasonInfo
from nflpool.data.dbsession import DbSessionFactory
from requests.auth import HTTPBasicAuth
import requests
import pendulum
import nflpool.data.secret as secret


            new_season = SeasonInfo(
                season_start_date=first_game_date,
                home_team=home_team,
                away_team=away_team,
                current_season=season,
            )

            session.add(new_season)
            session.commit()

        else:
            print("Existing season found, updating to new year")

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

            gameday_json = response.json()
            gameday_data = gameday_json["games"][0]

            first_game_date = gameday_data["startTime"]
            home_team = gameday_data["homeTeam"]["id"]
            away_team = gameday_data["awayTeam"]["id"]

            first_game_calc = pendulum.parse(first_game_date)


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