This commit is contained in:
2025-02-07 21:17:53 -05:00
parent 8c3cd423fe
commit 949c795fd1
3 changed files with 51 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ from typing import List, Dict, Optional
import pandas as pd
from sqlalchemy.exc import SQLAlchemyError
from app.schemas.file import CreateFileRequest
import os
logger = logging.getLogger(__name__)
@@ -53,6 +54,14 @@ class TCGPlayerService:
self.df_util = DataframeUtil()
self.file_service = file_service
def get_cookies_from_file(self) -> Dict:
# check if cookies file exists
if not os.path.exists('cookies/tcg_cookies.json'):
raise ValueError("Cookies file not found")
with open('cookies/tcg_cookies.json', 'r') as f:
cookies = json.load(f)
return cookies
def _insert_groups(self, groups):
for group in groups:
db_group = TCGPlayerGroups(
@@ -118,9 +127,11 @@ class TCGPlayerService:
logger.info(f"Waiting 10 seconds before next request...")
time.sleep(10 - time_diff)
headers = self._set_headers(method)
if not self.cookies:
# only get cookies on mac os not in docker container
if not self.cookies and os.name != 'nt':
self.cookies = self._get_browser_cookies()
else:
self.cookies = self.get_cookies_from_file()
if not self.cookies:
raise ValueError("Failed to retrieve browser cookies")