Mr-Thop commited on
Commit
03e70e3
·
1 Parent(s): 11b1f01
Files changed (1) hide show
  1. app.py +67 -6
app.py CHANGED
@@ -12,6 +12,7 @@ from Evaluator import InterviewEvaluator
12
  import json
13
  import os
14
  import pandas as pd
 
15
  # At the top with imports
16
  from werkzeug.utils import secure_filename
17
 
@@ -56,6 +57,51 @@ def allowed_file(filename):
56
  return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
57
 
58
  # Add this endpoint (before /parse)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  @app.route("/test-upload", methods=["POST"])
60
  def test_upload():
61
  try:
@@ -87,8 +133,8 @@ def upload_candidate_list():
87
  return jsonify({"error": "No file selected"}), 400
88
 
89
  if file and file.filename.endswith('.csv'):
90
- # Save as test.csv for the scheduler to use
91
- filepath = os.path.join('.', 'test.csv')
92
  file.save(filepath)
93
  logging.info(f"Saved CSV file to: {filepath}")
94
 
@@ -103,6 +149,13 @@ def upload_candidate_list():
103
  "found_columns": list(df.columns)
104
  }), 400
105
 
 
 
 
 
 
 
 
106
  logging.info(f"Successfully validated CSV with {len(df)} candidates")
107
  return jsonify({
108
  "output": f"Successfully uploaded candidate list with {len(df)} candidates",
@@ -381,10 +434,18 @@ def email():
381
  if not date or not time or not slot_length:
382
  return jsonify({"error": "Missing required fields: date, time, or length"}), 400
383
 
384
- # Check if CSV file exists
385
- csv_path = "./test.csv"
386
- if not os.path.exists(csv_path):
387
- return jsonify({"error": "Candidate list file (test.csv) not found"}), 400
 
 
 
 
 
 
 
 
388
 
389
  scheduler = Schedule()
390
  scheduler.defaults(date, time, slot_length)
 
12
  import json
13
  import os
14
  import pandas as pd
15
+ import shutil
16
  # At the top with imports
17
  from werkzeug.utils import secure_filename
18
 
 
57
  return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
58
 
59
  # Add this endpoint (before /parse)
60
+ @app.route("/debug-permissions", methods=["GET"])
61
+ def debug_permissions():
62
+ try:
63
+ import tempfile
64
+
65
+ # Test various directories
66
+ test_results = {}
67
+
68
+ # Test current directory
69
+ try:
70
+ with open('./test_write.txt', 'w') as f:
71
+ f.write('test')
72
+ os.remove('./test_write.txt')
73
+ test_results['current_dir'] = 'writable'
74
+ except Exception as e:
75
+ test_results['current_dir'] = f'not writable: {str(e)}'
76
+
77
+ # Test /tmp directory
78
+ try:
79
+ with open('/tmp/test_write.txt', 'w') as f:
80
+ f.write('test')
81
+ os.remove('/tmp/test_write.txt')
82
+ test_results['tmp_dir'] = 'writable'
83
+ except Exception as e:
84
+ test_results['tmp_dir'] = f'not writable: {str(e)}'
85
+
86
+ # Test temp directory
87
+ try:
88
+ temp_dir = tempfile.gettempdir()
89
+ test_path = os.path.join(temp_dir, 'test_write.txt')
90
+ with open(test_path, 'w') as f:
91
+ f.write('test')
92
+ os.remove(test_path)
93
+ test_results['temp_dir'] = f'writable: {temp_dir}'
94
+ except Exception as e:
95
+ test_results['temp_dir'] = f'not writable: {str(e)}'
96
+
97
+ return jsonify({
98
+ "current_working_dir": os.getcwd(),
99
+ "write_permissions": test_results
100
+ })
101
+
102
+ except Exception as e:
103
+ return jsonify({"error": str(e)}), 500
104
+
105
  @app.route("/test-upload", methods=["POST"])
106
  def test_upload():
107
  try:
 
133
  return jsonify({"error": "No file selected"}), 400
134
 
135
  if file and file.filename.endswith('.csv'):
136
+ # Use /tmp directory which should be writable
137
+ filepath = '/tmp/test.csv'
138
  file.save(filepath)
139
  logging.info(f"Saved CSV file to: {filepath}")
140
 
 
149
  "found_columns": list(df.columns)
150
  }), 400
151
 
152
+ # Also copy to the current directory for backward compatibility
153
+ try:
154
+ shutil.copy(filepath, './test.csv')
155
+ logging.info("Also copied to ./test.csv")
156
+ except Exception as copy_error:
157
+ logging.warning(f"Could not copy to ./test.csv: {copy_error}")
158
+
159
  logging.info(f"Successfully validated CSV with {len(df)} candidates")
160
  return jsonify({
161
  "output": f"Successfully uploaded candidate list with {len(df)} candidates",
 
434
  if not date or not time or not slot_length:
435
  return jsonify({"error": "Missing required fields: date, time, or length"}), 400
436
 
437
+ # Check for CSV file in multiple locations
438
+ csv_paths = ["/tmp/test.csv", "./test.csv"]
439
+ csv_path = None
440
+
441
+ for path in csv_paths:
442
+ if os.path.exists(path):
443
+ csv_path = path
444
+ logging.info(f"Found CSV file at: {csv_path}")
445
+ break
446
+
447
+ if not csv_path:
448
+ return jsonify({"error": "Candidate list file not found. Please upload a CSV file first."}), 400
449
 
450
  scheduler = Schedule()
451
  scheduler.defaults(date, time, slot_length)