Skip to content

Commit

Permalink
set up firebase and data loading
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-hsieh committed Nov 9, 2023
1 parent c2fdbae commit 62f7239
Show file tree
Hide file tree
Showing 8 changed files with 656 additions and 66 deletions.
40 changes: 27 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# Third-party imports
from flask import Flask, jsonify, request
import json

from flask_cors import CORS, cross_origin
from dotenv import load_dotenv
import os
from flask_cors import CORS

Check warning on line 6 in app.py

View check run for this annotation

Codecov / codecov/patch

app.py#L4-L6

Added lines #L4 - L6 were not covered by tests
# from decouple import config
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

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

Check warning on line 15 in app.py

View check run for this annotation

Codecov / codecov/patch

app.py#L13-L15

Added lines #L13 - L15 were not covered by tests

cred = credentials.Certificate("./key.json")
firebase_admin.initialize_app(cred)
cred = credentials.Certificate(CREDS)
if not firebase_admin._apps:
firebase_admin.initialize_app(cred, {

Check warning on line 19 in app.py

View check run for this annotation

Codecov / codecov/patch

app.py#L17-L19

Added lines #L17 - L19 were not covered by tests
'databaseURL': DATABASE_URL
})


# app.config['SQLALCHEMY_DATABASE_URI'] = config('DATABASE_URL')
Expand All @@ -31,10 +38,6 @@ def hello1():
@app.route('/test_submodule', methods=['GET'])
def submodule():
matchups = get_current_matchups()
for matchup_index, matchup in enumerate(matchups):
away = matchup.away_lineup
for player_index, player in enumerate(away):
team = matchup.away_team.team_name

return jsonify(str(matchups))

Expand Down Expand Up @@ -63,18 +66,29 @@ def highest_score():

@app.route('/most_points_get', methods=['GET'])
def calculate_most_points_get():
contest_dict = {}

Check warning on line 69 in app.py

View check run for this annotation

Codecov / codecov/patch

app.py#L69

Added line #L69 was not covered by tests
stat = 'total_lb_points'
points = get_most_position_points(
contests[stat]['position_list'], current_week()-1)
ranks = order_positions_by_points(points)
return jsonify(ranks)
contest_dict['contest_results'] = order_positions_by_points(points)
contest_dict['contest'] = stat
return jsonify(contest_dict)

Check warning on line 75 in app.py

View check run for this annotation

Codecov / codecov/patch

app.py#L73-L75

Added lines #L73 - L75 were not covered by tests


@app.route('/most_points_post', methods=['POST'])
def calculate_most_points_post():
output_dict = {}
contest_dict = {}

Check warning on line 81 in app.py

View check run for this annotation

Codecov / codecov/patch

app.py#L80-L81

Added lines #L80 - L81 were not covered by tests
point_request = request.get_json()
stat = point_request['contest']
week = point_request['week']
year = point_request['year']

Check warning on line 85 in app.py

View check run for this annotation

Codecov / codecov/patch

app.py#L84-L85

Added lines #L84 - L85 were not covered by tests
points = get_most_position_points(
contests[stat]['position_list'], current_week())
ranks = order_positions_by_points(points)
return jsonify(ranks)
contests[stat]['position_list'], week)
contest_dict['contest_results'] = order_positions_by_points(points)
contest_dict['contest'] = stat
output_week = "week_" + str(week)
output_dict[output_week] = contest_dict
ref = db.reference("/" + str(year))
ref.push(output_dict)
return '{"status":"200", "data": "OK"}'

Check warning on line 94 in app.py

View check run for this annotation

Codecov / codecov/patch

app.py#L88-L94

Added lines #L88 - L94 were not covered by tests
Loading

0 comments on commit 62f7239

Please sign in to comment.