Update app.py
Browse files4 unmodified lines567891011180 unmodified lines19219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822917 unmodified lines2472482492502512522532542552561 unmodified line2582592602612622632642652662672682692702712722732742752762772782792802812822832842852864 unmodified linesimport sys# Disable Streamlit's telemetry and usage statistics# This prevents it from trying to write to /.streamlit directoryos.environ['STREAMLIT_ANALYTICS_ENABLED'] = 'false'os.environ['STREAMLIT_METRICS_ENABLED'] = 'false'os.environ['STREAMLIT_BROWSER_GATHER_USAGE_STATS'] = '0'180 unmodified lines"Done": "done"}# Determine the best place to store data based on environmentdef get_data_path():"""Determine the best location for data storage based on environment"""# Try several possible locations in order of preferencepossible_locations = [os.path.join(os.getcwd(), "data"), # Current working directoryos.path.join(os.getcwd()), # Root of application"/tmp", # Temporary directory (works on most platforms)"/app/data", # Common docker app data directory"/data" # Original location (may not be writable)]for location in possible_locations:try:# Test if we can write to this locationtest_file = os.path.join(location, "test_write.txt")os.makedirs(location, exist_ok=True)with open(test_file, 'w') as f:f.write('test')os.remove(test_file)return locationexcept (PermissionError, OSError):continue# If we get here, we couldn't find a writable location# Just use current directory without writing to diskreturn os.getcwd()# Set up pathsDATA_DIR = get_data_path()TASKS_FILE = os.path.join(DATA_DIR, "tasks.csv")ASSIGNEE_FILE = os.path.join(DATA_DIR, "Assignee.txt")def create_empty_df():"""Create an empty DataFrame with the required columns"""17 unmodified linesdef save_tasks():"""Save tasks to CSV file with better error handling"""try:# Make sure parent directory existsos.makedirs(os.path.dirname(TASKS_FILE), exist_ok=True)# Save with appropriate permissionsst.session_state.tasks.to_csv(TASKS_FILE, index=False)return Trueexcept Exception:1 unmodified linereturn Falsedef load_assignees():"""Load assignees from text file or use defaults"""default_assignees = ["John Doe", "Jane Smith", "Alex Johnson", "Maria Garcia"]try:if not os.path.exists(ASSIGNEE_FILE):# Create a sample filetry:with open(ASSIGNEE_FILE, "w") as f:f.write("John Doe - Producer\nJane Smith - Director\nAlex Johnson - Camera Operator\nMaria Garcia - Editor\n")except:return default_assigneesassignees = []with open(ASSIGNEE_FILE, "r") as f:lines = [line.strip() for line in f.readlines() if line.strip()]for line in lines:if '-' in line:name_part = line.split('-')[0].strip()if ' ' in name_part:assignees.append(name_part)return assignees if assignees else default_assigneesexcept Exception:return default_assignees# Initialize session state ONLY ONCE4 unmodified lines5678910180 unmodified lines19119219319419519619719819920020120220320420520620720820921021121221321421517 unmodified lines2332342352362372381 unmodified line2402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822834 unmodified linesimport sys# Disable Streamlit's telemetry and usage statisticsos.environ['STREAMLIT_ANALYTICS_ENABLED'] = 'false'os.environ['STREAMLIT_METRICS_ENABLED'] = 'false'os.environ['STREAMLIT_BROWSER_GATHER_USAGE_STATS'] = '0'180 unmodified lines"Done": "done"}# Set up pathsTASKS_FILE = "tasks.csv" # Simplified path for tasks# Check all possible locations for Assignee.txtdef find_assignee_file():possible_locations = ["Assignee.txt", # Root directory"./Assignee.txt", # Explicit current directory"/app/Assignee.txt", # Docker app directoryos.path.join(os.getcwd(), "Assignee.txt"), # Full path to current directory"/data/Assignee.txt", # Data directory"../Assignee.txt", # Parent directory]for location in possible_locations:if os.path.exists(location):return locationreturn Nonedef create_empty_df():"""Create an empty DataFrame with the required columns"""17 unmodified linesdef save_tasks():"""Save tasks to CSV file with better error handling"""try:st.session_state.tasks.to_csv(TASKS_FILE, index=False)return Trueexcept Exception:1 unmodified linereturn Falsedef load_assignees():"""Load assignees from text file with extensive debugging and fallbacks"""default_assignees = ["John Doe", "Jane Smith", "Alex Johnson", "Maria Garcia"]# Find the Assignee.txt fileassignee_file_path = find_assignee_file()if not assignee_file_path:# Debugging: log available files in the current directoryfiles_in_cwd = os.listdir(os.getcwd())print(f"Files in current directory: {files_in_cwd}")return default_assigneestry:assignees = []with open(assignee_file_path, "r") as f:content = f.read()# Debug: Print the content of the fileprint(f"Content of {assignee_file_path}: {content}")lines = [line.strip() for line in content.split('\n') if line.strip()]for line in lines:if '-' in line:name_part = line.split('-')[0].strip()if ' ' in name_part:assignees.append(name_part)else:# If there's no dash, just use the whole line if it has a spaceif ' ' in line:assignees.append(line)# If we successfully parsed assignees, return themif assignees:return assignees# If no assignees were extracted, return defaultsreturn default_assigneesexcept Exception as e:print(f"Error loading assignees: {str(e)}")return default_assignees# Initialize session state ONLY ONCE
app.py+41-44