mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-12 05:42:59 +00:00
Update stock_manager.py
return temporary directory and stock logo downloading. Need to find a better way to handle this
This commit is contained in:
@@ -43,47 +43,47 @@ class StockManager:
|
|||||||
if not os.path.exists(self.ticker_icons_dir):
|
if not os.path.exists(self.ticker_icons_dir):
|
||||||
logger.warning(f"Ticker icons directory not found: {self.ticker_icons_dir}")
|
logger.warning(f"Ticker icons directory not found: {self.ticker_icons_dir}")
|
||||||
|
|
||||||
# # Set up the logo directory for external logos
|
# Set up the logo directory for external logos
|
||||||
# self.logo_dir = os.path.join('assets', 'stocks')
|
self.logo_dir = os.path.join('assets', 'stocks')
|
||||||
|
|
||||||
# # Check if we can use the logo directory, otherwise use temporary
|
# Check if we can use the logo directory, otherwise use temporary
|
||||||
# try:
|
try:
|
||||||
# if not os.path.exists(self.logo_dir):
|
if not os.path.exists(self.logo_dir):
|
||||||
# try:
|
try:
|
||||||
# os.makedirs(self.logo_dir, mode=0o755, exist_ok=True)
|
os.makedirs(self.logo_dir, mode=0o755, exist_ok=True)
|
||||||
# logger.info(f"Created logo directory: {self.logo_dir}")
|
logger.info(f"Created logo directory: {self.logo_dir}")
|
||||||
# except (PermissionError, OSError) as e:
|
except (PermissionError, OSError) as e:
|
||||||
# logger.warning(f"Cannot create logo directory '{self.logo_dir}': {str(e)}. Using temporary directory.")
|
logger.warning(f"Cannot create logo directory '{self.logo_dir}': {str(e)}. Using temporary directory.")
|
||||||
# import tempfile
|
import tempfile
|
||||||
# self.logo_dir = tempfile.mkdtemp(prefix='stock_logos_')
|
self.logo_dir = tempfile.mkdtemp(prefix='stock_logos_')
|
||||||
# writable = False # Explicitly set writable to false if creation fails
|
writable = False # Explicitly set writable to false if creation fails
|
||||||
# else:
|
else:
|
||||||
# writable = True # Assume writable if created successfully
|
writable = True # Assume writable if created successfully
|
||||||
# else:
|
else:
|
||||||
# # Directory exists, check if writable by trying to create a temp file
|
# Directory exists, check if writable by trying to create a temp file
|
||||||
# try:
|
try:
|
||||||
# temp_file_path = os.path.join(self.logo_dir, "write_test_py.tmp")
|
temp_file_path = os.path.join(self.logo_dir, "write_test_py.tmp")
|
||||||
# with open(temp_file_path, 'w') as f:
|
with open(temp_file_path, 'w') as f:
|
||||||
# f.write('test')
|
f.write('test')
|
||||||
# os.remove(temp_file_path)
|
os.remove(temp_file_path)
|
||||||
# writable = True
|
writable = True
|
||||||
# except (PermissionError, OSError) as e:
|
except (PermissionError, OSError) as e:
|
||||||
# logger.warning(f"Cannot write to logo directory '{self.logo_dir}' (write test failed): {e}. Using temporary directory.")
|
logger.warning(f"Cannot write to logo directory '{self.logo_dir}' (write test failed): {e}. Using temporary directory.")
|
||||||
# writable = False
|
writable = False
|
||||||
|
|
||||||
# # If not writable, switch to a temporary directory
|
# If not writable, switch to a temporary directory
|
||||||
# if not writable:
|
if not writable:
|
||||||
# import tempfile
|
import tempfile
|
||||||
# self.logo_dir = tempfile.mkdtemp(prefix='stock_logos_')
|
self.logo_dir = tempfile.mkdtemp(prefix='stock_logos_')
|
||||||
|
|
||||||
# logger.info(f"Using logo directory: {self.logo_dir}")
|
logger.info(f"Using logo directory: {self.logo_dir}")
|
||||||
|
|
||||||
# except Exception as e:
|
except Exception as e:
|
||||||
# logger.error(f"Error setting up logo directory: {str(e)}")
|
logger.error(f"Error setting up logo directory: {str(e)}")
|
||||||
# # Fall back to using a temporary directory
|
# Fall back to using a temporary directory
|
||||||
# import tempfile
|
import tempfile
|
||||||
# self.logo_dir = tempfile.mkdtemp(prefix='stock_logos_')
|
self.logo_dir = tempfile.mkdtemp(prefix='stock_logos_')
|
||||||
# logger.info(f"Using temporary directory for logos: {self.logo_dir}")
|
logger.info(f"Using temporary directory for logos: {self.logo_dir}")
|
||||||
|
|
||||||
self.headers = {
|
self.headers = {
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
||||||
|
|||||||
Reference in New Issue
Block a user