Fix tmp for mac

This commit is contained in:
Helper 2024-04-09 10:40:51 +02:00
parent e91e1b1aad
commit cba0536b39
2 changed files with 36 additions and 5 deletions

View File

@ -6,7 +6,6 @@ import os
import random import random
import threading import threading
import json import json
import tempfile
from typing import Dict, List from typing import Dict, List
# Internal utilities # Internal utilities
@ -48,6 +47,28 @@ def update_user_agents(browser_name: str, browser_user_agents: Dict[str, List[st
browser_user_agents[browser_name] = get_browser_user_agents_online(browser_name) browser_user_agents[browser_name] = get_browser_user_agents_online(browser_name)
def create_temp_directory():
"""
Create the TEMP directory if it doesn't exist.
If the TEMP environment variable doesn't exist, this function creates
the TEMP directory in the user's local AppData folder.
Returns:
str: The path to the TEMP directory.
"""
# Get the TEMP directory from the environment variables
temp_dir = os.environ.get('TEMP')
# If TEMP directory is not set, create it in the local AppData folder
if temp_dir is None:
temp_dir = os.path.join(os.path.expanduser("~"), "AppData", "Local", "Temp")
os.makedirs(temp_dir, exist_ok=True)
return temp_dir
def create_or_update_user_agent_file() -> None: def create_or_update_user_agent_file() -> None:
""" """
Create or update the user agent file with browser user agents. Create or update the user agent file with browser user agents.
@ -80,8 +101,11 @@ class UserAgentManager:
""" """
def __init__(self): def __init__(self):
# Create temp directory if not exist
temp_dir = create_temp_directory()
# Get path to temp file where save all user agents # Get path to temp file where save all user agents
self.user_agent_file = os.path.join(tempfile.gettempdir(), 'fake_user_agent.json') self.user_agent_file = os.path.join(temp_dir, 'fake_user_agent.json')
# If file dont exist, creaet it # If file dont exist, creaet it
if not os.path.exists(self.user_agent_file): if not os.path.exists(self.user_agent_file):

View File

@ -4,14 +4,21 @@
# run somehwere backup # run somehwere backup
# add config to trace if ffmpeg is install, using config in local or temp # add config to trace if ffmpeg is install, using config in local or temp
import winreg import platform
import os import os
import logging import logging
# Winreg only work for windows
if platform.system() == "Windows":
import winreg
# Define Windows registry key for user environment variables # Define Windows registry key for user environment variables
env_keys = winreg.HKEY_CURRENT_USER, "Environment" env_keys = winreg.HKEY_CURRENT_USER, "Environment"
else:
env_keys = None
def get_env(name: str) -> str: def get_env(name: str) -> str:
""" """