@@ -49,17 +49,21 @@ jobs:
4949 shell : pwsh
5050 run : |
5151 python -V
52- $script = @'
53- import importlib
54- for mod in ("nflreadpy", "nfl_data_py") :
55- try :
56- m = importlib.import_module(mod)
57- ver = getattr(m, "__version__", "(no __version__)")
58- print(f"{mod} version : {ver}")
59- except Exception as exc :
60- print(f"{mod} not importable : {exc}")
61- ' @
62- $script | python -
52+ $scriptLines = @(
53+ "import importlib",
54+ "",
55+ "for mod in ('nflreadpy', 'nfl_data_py'):",
56+ " try:",
57+ " m = importlib.import_module(mod)",
58+ " ver = getattr(m, '__version__', '(no __version__)')",
59+ " print(f'{mod} version: {ver}')",
60+ " except Exception as exc:",
61+ " print(f'{mod} not importable: {exc}')"
62+ )
63+ $temp = New-TemporaryFile
64+ Set-Content -Path $temp -Value $scriptLines
65+ python $temp
66+ Remove-Item $temp
6367
6468 - name : Run weekly loader
6569 shell : pwsh
@@ -82,34 +86,37 @@ for mod in ("nflreadpy", "nfl_data_py"):
8286 if : ${{ success() && env.PGHOST && env.PGUSER && env.PGDATABASE }}
8387 shell : pwsh
8488 run : |
85- $script = @'
86- import os
87- import sys
88- import pandas as pd
89- from sqlalchemy import create_engine
90-
91- csv_path = "nfl_weekly_stats.csv"
92- if not os.path.exists(csv_path) :
93- print(f"CSV not found : {csv_path}")
94- sys.exit(1)
95-
96- user = os.environ["PGUSER"]
97- pwd = os.environ["PGPASSWORD"]
98- host = os.environ["PGHOST"]
99- port = os.environ.get("PGPORT", "5432")
100- db = os.environ["PGDATABASE"]
101-
102- try :
103- import psycopg # noqa: F401
104- driver = "psycopg"
105- except ImportError :
106- driver = "psycopg2"
107-
108- url = f"postgresql+{driver}://{user}:{pwd}@{host}:{port}/{db}"
109- engine = create_engine(url)
110-
111- df = pd.read_csv(csv_path)
112- df.to_sql('nfl_weekly_stats', engine, if_exists='append', index=False)
113- print('Loaded CSV into Postgres table nfl_weekly_stats')
114- ' @
115- $script | python -
89+ $scriptLines = @(
90+ "import os",
91+ "import sys",
92+ "import pandas as pd",
93+ "from sqlalchemy import create_engine",
94+ "",
95+ "csv_path = 'nfl_weekly_stats.csv'",
96+ "if not os.path.exists(csv_path):",
97+ " print(f'CSV not found: {csv_path}')",
98+ " sys.exit(1)",
99+ "",
100+ "user = os.environ['PGUSER']",
101+ "pwd = os.environ['PGPASSWORD']",
102+ "host = os.environ['PGHOST']",
103+ "port = os.environ.get('PGPORT', '5432')",
104+ "db = os.environ['PGDATABASE']",
105+ "",
106+ "try:",
107+ " import psycopg # noqa: F401",
108+ " driver = 'psycopg'",
109+ "except ImportError:",
110+ " driver = 'psycopg2'",
111+ "",
112+ "url = f'postgresql+{driver}://{user}:{pwd}@{host}:{port}/{db}'",
113+ "engine = create_engine(url)",
114+ "",
115+ "df = pd.read_csv(csv_path)",
116+ "df.to_sql('nfl_weekly_stats', engine, if_exists='append', index=False)",
117+ "print('Loaded CSV into Postgres table nfl_weekly_stats')"
118+ )
119+ $temp = New-TemporaryFile
120+ Set-Content -Path $temp -Value $scriptLines
121+ python $temp
122+ Remove-Item $temp
0 commit comments