diff --git a/app.py b/app.py index 2587ae5..f2ced0b 100644 --- a/app.py +++ b/app.py @@ -8,17 +8,15 @@ 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') -CREDS = os.getenv('CREDS') +# DATABASE_URL = os.getenv('DATABASE_URL') +CREDS = os.getenv('CREEDS') cred = credentials.Certificate(CREDS) 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') @@ -72,23 +70,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"}' diff --git a/fantasy_app/functions.py b/fantasy_app/functions.py index 909bb04..97ce4b1 100644 --- a/fantasy_app/functions.py +++ b/fantasy_app/functions.py @@ -1,5 +1,5 @@ import os -import json +# import json import operator from datetime import datetime from dotenv import load_dotenv @@ -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: @@ -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: