Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
Updated user login to rely on .env file
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffjohannsen committed Dec 7, 2023
1 parent 2399c66 commit 406a525
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/deployment/web_app/nba_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
load_dotenv()
DB_ENDPOINT = os.getenv("DB_ENDPOINT")
DB_PASSWORD = os.getenv("DB_PASSWORD")
WEB_APP_USERNAME = os.getenv("WEB_APP_USERNAME")
WEB_APP_PASSWORD = os.getenv("WEB_APP_PASSWORD")
WEB_APP_SECRET_KEY = os.getenv("WEB_APP_SECRET_KEY")
ODDS_API_KEY = os.getenv("ODDS_API_KEY")

Expand Down Expand Up @@ -99,8 +101,8 @@ def check_password(self, password):

@login_manager.user_loader
def load_user(user_id):
admin_username = "jeff"
admin_password = os.getenv("DB_PASSWORD")
admin_username = WEB_APP_USERNAME
admin_password = WEB_APP_PASSWORD
if user_id == admin_username:
return User(
id=admin_username, username=admin_username, password=admin_password
Expand Down Expand Up @@ -249,6 +251,7 @@ def nba_data_inbound():
money_in_play = round(money_in_play)

records_df = pd.DataFrame(game_table)
records_df["game_datetime"] = pd.to_datetime(records_df["game_datetime"])

records_df["game_result"] = records_df.apply(
lambda row: int(row["home_score"] - row["away_score"])
Expand Down Expand Up @@ -335,8 +338,9 @@ def logout():

@app.route("/", methods=["POST", "GET"])
def home_table():
if current_user.is_authenticated:
on_demand_update()
# On demand update is turned off unless live data source is available.
# if current_user.is_authenticated:
# on_demand_update()

data = nba_data_inbound()
if request.method == "POST":
Expand Down Expand Up @@ -406,8 +410,9 @@ def home_table():
},
)

if current_user.is_authenticated:
on_demand_update()
# On demand update is turned off unless live data source is available.
# if current_user.is_authenticated:
# on_demand_update()
data = nba_data_inbound()
return render_template("nba_home.html", **data)

Expand Down Expand Up @@ -440,7 +445,7 @@ def create_figure():
balance
FROM (SELECT *,
row_number()
OVER (PARTITION BY date_trunc('day', datetime)
OVER (PARTITION BY date_trunc('day', datetime::timestamp)
ORDER BY datetime DESC) r
FROM betting_account) T
WHERE T.r=1;"""
Expand Down Expand Up @@ -481,5 +486,5 @@ def add_header(r):
public_app = init_public_dashboard(app)

if __name__ == "__main__":
pass
# app.run(debug=True)
# pass
app.run(debug=True)

0 comments on commit 406a525

Please sign in to comment.