Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix functions #20

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,4 @@ venv.bak/
key.json
.ipynb

db.ipynb
21 changes: 11 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
from fantasy_app.functions import get_current_matchups, current_week, get_most_position_points, order_positions_by_points
from fantasy_app.contest_list import contests
import firebase_admin
from firebase_admin import credentials, db
from firebase_admin import credentials, firestore

load_dotenv()
DATABASE_URL = os.getenv('DATABASE_URL')
# DATABASE_URL = os.getenv('DATABASE_URL')
CREDS = os.getenv('CREEDS')


cred = credentials.Certificate("./CREDS.json")
if not firebase_admin._apps:
firebase_admin.initialize_app(cred, {
'databaseURL': DATABASE_URL
})
firebase_admin.initialize_app(cred)


# app.config['SQLALCHEMY_DATABASE_URI'] = config('DATABASE_URL')
Expand Down Expand Up @@ -71,23 +71,24 @@ def calculate_most_points_get():
contests[stat]['position_list'], current_week()-1)
contest_dict['contest_results'] = order_positions_by_points(points)
contest_dict['contest'] = stat

return jsonify(contest_dict)


@app.route('/most_points_post', methods=['POST'])
def calculate_most_points_post():
output_dict = {}
contest_dict = {}
point_request = request.get_json()
stat = point_request['contest']
week = point_request['week']
week = int(point_request['week'])
year = point_request['year']
points = get_most_position_points(
contests[stat]['position_list'], week)
contest_dict['contest_results'] = order_positions_by_points(points)
contest_dict['contest'] = stat
contest_dict['week'] = week
output_week = "week_" + str(week)
output_dict[output_week] = contest_dict
ref = db.reference("/" + str(year))
ref.push(output_dict)
db = firestore.client()
doc_ref = db.collection(year).document(output_week)
doc_ref.set(contest_dict)
return '{"status":"200", "data": "OK"}'
15 changes: 7 additions & 8 deletions fantasy_app/functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import json
# import json
import operator
from datetime import datetime
from dotenv import load_dotenv
Expand All @@ -8,12 +8,14 @@

# load environment variables
load_dotenv()
LEAGUE_ID = os.getenv('LEAGU2')
SWID = os.getenv('SWID')
LEAGUE_ID = os.getenv('LEAGUE_ID')
ESPN_S2 = os.getenv('ESPN_S2')
SWID = os.getenv('SWID')


# retrieve football year


def get_year():
currentMonth = datetime.now().month
if currentMonth > 7:
Expand Down Expand Up @@ -145,11 +147,8 @@ def new_dict(position, current_dict, lineup):


def get_most_position_points(position, currentweek=0):
if currentweek > 0:
matchups = league.box_scores(currentweek)
else:
matchups = get_current_matchups()
currentweek = current_week()
matchups = league.box_scores(currentweek)

matchups_list = []

for matchup in matchups:
Expand Down
Loading