Skip to content

Commit

Permalink
Sandbox URL Creation
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeebot[bot] authored Mar 26, 2024
1 parent 9b82bd1 commit b714e1a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
11 changes: 5 additions & 6 deletions backend-container/src/apimappings/PushFeeds.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import requests
import json
import os
from threading import Thread
import src.utils.log as be_logger
import src.utils.logandcatchexceptions as logandcatchexceptions
import time
from security import safe_requests

load_dotenv()

current_dir = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -26,11 +25,11 @@
# Function to handle the subscription and be_logger.infoing of data@log_and_catch_exceptions
def subscribe_to_feed(feed_url, params):
while True:
with requests.get(feed_url, params=params, allow_redirects=False, stream=True) as r:
with safe_requests.get(feed_url, params=params, allow_redirects=False, stream=True) as r:
if r.status_code == 200:
redirect_url = r.headers['Location']
be_logger.info(f"Listening for data on {feed_url}")
with requests.get(redirect_url, stream=True) as stream:
with safe_requests.get(redirect_url, stream=True) as stream:
for line in stream.iter_lines():
if line:
decoded_line = line.decode('utf-8')
Expand Down Expand Up @@ -62,4 +61,4 @@ def start_subscriptions(api_key):

# Keep the main thread running to keep the subscription threads alive
for thread in threads:
thread.join()
thread.join()
7 changes: 4 additions & 3 deletions backend-container/src/apimappings/current_season_schedule.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import sys
import requests
import time
from datetime import datetime
from flask import Blueprint, jsonify
from dotenv import load_dotenv
from security import safe_requests

load_dotenv()
from src.models.boxscore_info import (
gamebs, quarter, overtime, BoxscoreInfo)
Expand Down Expand Up @@ -36,7 +37,7 @@ def fetch_and_save_all_seasons_schedule():
for season_type in ['REG', 'PST']:
url = SEASONS_API_URL.format(year=year, season_type=season_type, API_KEY=API_KEY)
be_logger.info(f"Requesting URL at {datetime.now()}: {fetch_and_save_all_seasons_schedule}")
response = requests.get(url)
response = safe_requests.get(url)
be_logger.info(f"Response status code for {fetch_and_save_all_seasons_schedule}: {response.status_code}")

if response.status_code != 200:
Expand Down Expand Up @@ -74,7 +75,7 @@ def fetch_and_save_weekly_schedule():
url = WEEKLY_SCHEDULE_API_URL.format(
season_year=season_year, season_type=season_type, week_number=week_number, API_KEY=API_KEY)
be_logger.info(f"{datetime.now()} Requesting URL: {url}")
response = requests.get(url)
response = safe_requests.get(url)
be_logger.info(f"Response status code: {response.status_code}")
if response.status_code != 200:
return f"GetCurrentSeasonScheduleError for {season_year} {season_type} {week_number}: {response.status_code}"
Expand Down
10 changes: 5 additions & 5 deletions backend-container/src/sportsradar/simulation/gamefeeds.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import requests
from src.sportsradar.simulation.available_recordings import AvailableRecordings
from src.sportsradar.simulation.session import create_session
from src.sportsradar.simulation.config import Config
from security import safe_requests

GAME_FEEDS_TYPE = "replay"

Expand Down Expand Up @@ -47,7 +47,7 @@ def get_game_boxscore(recording_id, session_id):
* status code. The JSON response is returned as the result of the method.
"""
url = f"{Config.BASE_URL}/{GAME_FEEDS_TYPE}/{Config.LEAGUE}/{recording_id}?feed=boxscore&contentType={Config.CONTENT_TYPE}&sessionId={session_id}"
response = requests.get(url=url, timeout=60)
response = safe_requests.get(url=url, timeout=60)
if response.status_code != 200:
raise Exception(f"Request failed with status code: {response.status_code}")
return response.json()
Expand All @@ -62,7 +62,7 @@ def get_game_info(recording_id, session_id):
"""
url = f"{Config.BASE_URL}/{GAME_FEEDS_TYPE}/{Config.LEAGUE}/{recording_id}?feed=game&contentType={Config.CONTENT_TYPE}&sessionId={session_id}"
response = requests.get(url=url, timeout=60)
response = safe_requests.get(url=url, timeout=60)
if response.status_code != 200:
raise Exception(f"Request failed with status code: {response.status_code}")
return response.json()
Expand All @@ -77,7 +77,7 @@ def get_pbp_info(recording_id, session_id):
:return: The play-by-play information in JSON format.
"""
url = f"{Config.BASE_URL}/{GAME_FEEDS_TYPE}/{Config.LEAGUE}/{recording_id}?feed=pbp&contentType={Config.CONTENT_TYPE}&sessionId={session_id}"
response = requests.get(url=url, timeout=60)
response = safe_requests.get(url=url, timeout=60)
if response.status_code != 200:
raise Exception(f"Request failed with status code: {response.status_code}")
return response.json()
Expand All @@ -94,7 +94,7 @@ def get_game_roster(recording_id, session_id):
* with the corresponding status code.
"""
url = f"{Config.BASE_URL}/{GAME_FEEDS_TYPE}/{Config.LEAGUE}/{recording_id}?feed=rosters&contentType={Config.CONTENT_TYPE}&sessionId={session_id}"
response = requests.get(url=url, timeout=60)
response = safe_requests.get(url=url, timeout=60)
print(response)
if response.status_code != 200:
raise Exception(f"Request failed with status code: {response.status_code}")
Expand Down

0 comments on commit b714e1a

Please sign in to comment.