From b714e1a6ca6bfa7cbd5d76c8d8fd35df958825c1 Mon Sep 17 00:00:00 2001 From: "pixeebot[bot]" <104101892+pixeebot[bot]@users.noreply.github.com> Date: Tue, 26 Mar 2024 07:29:15 +0000 Subject: [PATCH] Sandbox URL Creation --- backend-container/src/apimappings/PushFeeds.py | 11 +++++------ .../src/apimappings/current_season_schedule.py | 7 ++++--- .../src/sportsradar/simulation/gamefeeds.py | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/backend-container/src/apimappings/PushFeeds.py b/backend-container/src/apimappings/PushFeeds.py index 492a1fcb..fc83e5a2 100644 --- a/backend-container/src/apimappings/PushFeeds.py +++ b/backend-container/src/apimappings/PushFeeds.py @@ -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__)) @@ -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') @@ -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() \ No newline at end of file + thread.join() diff --git a/backend-container/src/apimappings/current_season_schedule.py b/backend-container/src/apimappings/current_season_schedule.py index 433ebaac..3593c593 100644 --- a/backend-container/src/apimappings/current_season_schedule.py +++ b/backend-container/src/apimappings/current_season_schedule.py @@ -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) @@ -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: @@ -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}" diff --git a/backend-container/src/sportsradar/simulation/gamefeeds.py b/backend-container/src/sportsradar/simulation/gamefeeds.py index 74894cab..cd9471e2 100644 --- a/backend-container/src/sportsradar/simulation/gamefeeds.py +++ b/backend-container/src/sportsradar/simulation/gamefeeds.py @@ -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" @@ -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() @@ -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() @@ -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() @@ -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}")