Skip to content

Commit

Permalink
Merge branch 'main' into snyk-fix-ae24e85764c9ada6be83f7eca7a90b4b
Browse files Browse the repository at this point in the history
  • Loading branch information
zepor authored Jan 11, 2024
2 parents af0cfcf + 1831d99 commit 216cefb
Show file tree
Hide file tree
Showing 29 changed files with 3,819 additions and 2,693 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ spark-2.3.1-bin-hadoop2.7/
!.env.vault

NFL-Stats/
SportsRadar/
nextjs-container/
/backend-container/src/Schema/NFL_v7/*.py
/backend-container/src/Schema/NFL_v7/*.json
Expand Down
617 changes: 307 additions & 310 deletions backend-container/src/apimappings/LeagueHierarchy.py

Large diffs are not rendered by default.

33 changes: 7 additions & 26 deletions backend-container/src/apimappings/PBP.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
import base64
import json
import logging
import os
import pickle
import redis
import requests
import sys
import time
from datetime import datetime, timedelta
from itertools import groupby
from json import JSONEncoder
from logging.handlers import RotatingFileHandler
from operator import itemgetter
from threading import Thread
from apscheduler.schedulers.background import BackgroundScheduler
from bson import Binary, ObjectId
from dateutil.parser import parse
from dotenv import load_dotenv
from flask import Flask, Blueprint, jsonify, make_response, render_template, request, session
from flask_cors import CORS
from flask_mongoengine import MongoEngine
from src.models.play_by_play_info import (quarter, location, possession, start_location, play, score, detail, event, end_situation, start_situation, drive, description, penalty,defensive_team, offensive_team, period, points_after_play, PlayByPlayInfo)
from mongoengine import (connect, DecimalField, Document, EmbeddedDocument, EmbeddedDocumentField, EmbeddedDocumentListField, StringField, UUIDField, IntField, BooleanField, DateTimeField)
from datetime import datetime
from flask import Blueprint
from src.models.play_by_play_info import (quarter, location, possession, start_location, play, score)
from pymongo import MongoClient
from pymongo.errors import ConnectionFailure
from uuid import UUID
from waitress import serve
from security import safe_requests

sys.path.append("os.getenv('LPATH')/src/")
if not hasattr(os, 'add_dll_directory'):
def add_dll_directory(path):
Expand Down Expand Up @@ -69,7 +50,7 @@ def fetch_and_pbp_by_game(game_id):
print("fetch_and_pbp_by_game")
API_KEY = os.getenv('APIKEY')
PLAY_BY_PLAY_API_URL = f"https://api.sportradar.us/nfl/official/trial/v7/en/games/{game_id}/pbp.json?api_key={api_key}"
response = requests.get(PLAY_BY_PLAY_API_URL, timeout=10)
response = safe_requests.get(PLAY_BY_PLAY_API_URL, timeout=10)
print("Response status code:", response.status_code)
if response.status_code != 200:
return f"GetCurrentSeasonScheduleError for {game_id} {year}: {response.status_code}"
Expand Down Expand Up @@ -114,7 +95,7 @@ def process_games_for_year(year):
def extract_play_by_play_data(source):
# Fetch play-by-play data from the source (API, database, file, etc.)
# This is an example of extracting from an API
response = requests.get(source)
response = safe_requests.get(source)
return response.json()

@log_and_catch_exceptions
Expand Down
106 changes: 54 additions & 52 deletions backend-container/src/apimappings/SeasonInfoLists.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
import os, time
if not hasattr(os, 'add_dll_directory'):
def add_dll_directory(path):
pass
from mongoengine import connect
from src.models.seasons import(SeasonInfo)
from src.models.team_info import(coach, rgb_color, team, team_color, TeamInfo)
if not hasattr(os, 'add_dll_directory'):
def add_dll_directory(path):
pass
from dotenv import load_dotenv
load_dotenv()
connection_string = os.getenv('MONGODB_URL')
if not connection_string:
raise Exception("MONGO_CONNECTION_STRING must be set")
connect(db='Current_Season', host=connection_string)

from datetime import datetime
import requests
API_KEY = os.getenv('APIKEY')
URL = "http://api.sportradar.us/nfl/official/trial/v7/en/seasons/{SEASONYEAR}/{SEASONTYPE}/teams/{TeamID}/statistics.json?api_key={API_KEY}"
TEAMID = list({team.id for team in TeamInfo.objects.only("id")})
SEASONYEAR = list({season.year for season in SeasonInfo.objects.only("year")})
SEASONTYPE = list(
{season["type"] for season in SeasonInfo.objects.only("type")}
)
print(SEASONYEAR)
print(TEAMID)
print(SEASONTYPE)

counter = 0
try:
for team_id in TEAMID:
for year in SEASONYEAR:
for season_type in SEASONTYPE:
constructed_url = URL.format(SEASONYEAR=year, SEASONTYPE=season_type, TeamID=team_id)
print(datetime.now(), "Constructed URL:", constructed_url)
try:
response = requests.get(constructed_url)
if response.status_code != 200:
print(f"Error: API call to {constructed_url} returned status code: {response.status_code}")
except requests.exceptions.RequestException as req_e:
print(f"API request error for {constructed_url}. Error: {req_e}")
counter += 1
if counter >= 40:
break
if counter >= 40:
break
if counter >= 40:
break
except Exception as e:
print(f"Error: {str(e)}")
import os
from security import safe_requests

if not hasattr(os, 'add_dll_directory'):
def add_dll_directory(path):
pass
from mongoengine import connect
from src.models.seasons import(SeasonInfo)
from src.models.team_info import(TeamInfo)
if not hasattr(os, 'add_dll_directory'):
def add_dll_directory(path):
pass
from dotenv import load_dotenv
load_dotenv()
connection_string = os.getenv('MONGODB_URL')
if not connection_string:
raise Exception("MONGO_CONNECTION_STRING must be set")
connect(db='Current_Season', host=connection_string)

from datetime import datetime
import requests
API_KEY = os.getenv('APIKEY')
URL = "http://api.sportradar.us/nfl/official/trial/v7/en/seasons/{SEASONYEAR}/{SEASONTYPE}/teams/{TeamID}/statistics.json?api_key={API_KEY}"
TEAMID = list({team.id for team in TeamInfo.objects.only("id")})
SEASONYEAR = list({season.year for season in SeasonInfo.objects.only("year")})
SEASONTYPE = list(
{season["type"] for season in SeasonInfo.objects.only("type")}
)
print(SEASONYEAR)
print(TEAMID)
print(SEASONTYPE)

counter = 0
try:
for team_id in TEAMID:
for year in SEASONYEAR:
for season_type in SEASONTYPE:
constructed_url = URL.format(SEASONYEAR=year, SEASONTYPE=season_type, TeamID=team_id)
print(datetime.now(), "Constructed URL:", constructed_url)
try:
response = safe_requests.get(constructed_url)
if response.status_code != 200:
print(f"Error: API call to {constructed_url} returned status code: {response.status_code}")
except requests.exceptions.RequestException as req_e:
print(f"API request error for {constructed_url}. Error: {req_e}")
counter += 1
if counter >= 40:
break
if counter >= 40:
break
if counter >= 40:
break
except Exception as e:
print(f"Error: {str(e)}")
Loading

0 comments on commit 216cefb

Please sign in to comment.