Mr-Thop commited on
Commit
c84c366
·
1 Parent(s): 2b07db6
Files changed (2) hide show
  1. DB.py +2 -2
  2. app.py +90 -11
DB.py CHANGED
@@ -30,8 +30,8 @@ class DB:
30
  self.cursor_MS = self.connection_MS.cursor()
31
 
32
  def insert(self, data):
33
- insert_query = f"INSERT INTO users(name,email,date,time,password,score) VALUES %s"
34
- self.cursor_MS.execute(insert_query, (data,))
35
 
36
 
37
  def clear(self):
 
30
  self.cursor_MS = self.connection_MS.cursor()
31
 
32
  def insert(self, data):
33
+ insert_query = "INSERT INTO users(name,email,date,time,password,score) VALUES (%s,%s,%s,%s,%s,%s)"
34
+ self.cursor_MS.execute(insert_query, data)
35
 
36
 
37
  def clear(self):
app.py CHANGED
@@ -55,6 +55,48 @@ def allowed_file(filename):
55
  return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
56
 
57
  # Add this endpoint (before /parse)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  @app.route("/upload-resumes", methods=["POST"])
59
  def upload_resumes():
60
  try:
@@ -278,14 +320,31 @@ def score():
278
 
279
 
280
  def create_user(scheduler):
281
- db.connect_MS()
282
- df = scheduler.df
283
- for name,email,date,time in zip(df["Name"],df["Email"],scheduler.date,df["Slot"]):
284
- password = name[:5] + email[:5]
285
- db.insert([name,email,date,time,password,0.0])
286
-
287
- db.connection_MS.commit()
288
- db.close_MS()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
 
290
 
291
  @app.route("/schedule", methods = ["POST"])
@@ -296,13 +355,33 @@ def email():
296
  time = data.get("time")
297
  slot_length = data.get("length")
298
 
 
 
 
 
 
 
 
 
 
299
  scheduler = Schedule()
300
  scheduler.defaults(date, time, slot_length)
301
- scheduler.schedule_slots("./test.csv")
302
- create_user(scheduler) # Pass scheduler to create_user
 
 
 
 
303
  scheduler.send_emails()
304
 
305
- return jsonify({"output": "Emails Sent Successfully"})
 
 
 
 
 
 
 
306
  except Exception as e:
307
  logging.error(f"Scheduling error: {str(e)}")
308
  return jsonify({"error": "Failed to schedule interviews", "message": str(e)}), 500
 
55
  return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
56
 
57
  # Add this endpoint (before /parse)
58
+ @app.route("/upload-candidate-list", methods=["POST"])
59
+ def upload_candidate_list():
60
+ try:
61
+ if 'candidate_list' not in request.files:
62
+ return jsonify({"error": "No CSV file provided"}), 400
63
+
64
+ file = request.files['candidate_list']
65
+
66
+ if file.filename == '':
67
+ return jsonify({"error": "No file selected"}), 400
68
+
69
+ if file and file.filename.endswith('.csv'):
70
+ # Save as test.csv for the scheduler to use
71
+ filepath = os.path.join('.', 'test.csv')
72
+ file.save(filepath)
73
+
74
+ # Validate CSV format
75
+ import pandas as pd
76
+ try:
77
+ df = pd.read_csv(filepath)
78
+ required_columns = ['Name', 'Email']
79
+
80
+ if not all(col in df.columns for col in required_columns):
81
+ return jsonify({
82
+ "error": "CSV must have 'Name' and 'Email' columns",
83
+ "found_columns": list(df.columns)
84
+ }), 400
85
+
86
+ return jsonify({
87
+ "output": f"Successfully uploaded candidate list with {len(df)} candidates",
88
+ "candidates": len(df)
89
+ })
90
+
91
+ except Exception as e:
92
+ return jsonify({"error": f"Invalid CSV format: {str(e)}"}), 400
93
+ else:
94
+ return jsonify({"error": "File must be a CSV"}), 400
95
+
96
+ except Exception as e:
97
+ logging.error(f"CSV upload error: {str(e)}")
98
+ return jsonify({"error": str(e)}), 500
99
+
100
  @app.route("/upload-resumes", methods=["POST"])
101
  def upload_resumes():
102
  try:
 
320
 
321
 
322
  def create_user(scheduler):
323
+ try:
324
+ db.connect_MS()
325
+ df = scheduler.df
326
+
327
+ for name, email, slot in zip(df["Name"], df["Email"], df["Slot"]):
328
+ password = name[:5] + email[:5]
329
+ # Extract date and time from slot string
330
+ slot_parts = slot.split(" - ")
331
+ interview_datetime = slot_parts[0] # "2024-03-15 09:00"
332
+ date_part, time_part = interview_datetime.split(" ")
333
+
334
+ # Insert individual values, not as a list
335
+ db.insert([name, email, date_part, time_part, password, 0.0])
336
+
337
+ db.connection_MS.commit()
338
+ db.close_MS()
339
+ logging.info(f"Successfully created {len(df)} user records")
340
+
341
+ except Exception as e:
342
+ logging.error(f"Error creating users: {str(e)}")
343
+ try:
344
+ db.close_MS()
345
+ except:
346
+ pass
347
+ raise e
348
 
349
 
350
  @app.route("/schedule", methods = ["POST"])
 
355
  time = data.get("time")
356
  slot_length = data.get("length")
357
 
358
+ # Validate input
359
+ if not date or not time or not slot_length:
360
+ return jsonify({"error": "Missing required fields: date, time, or length"}), 400
361
+
362
+ # Check if CSV file exists
363
+ csv_path = "./test.csv"
364
+ if not os.path.exists(csv_path):
365
+ return jsonify({"error": "Candidate list file (test.csv) not found"}), 400
366
+
367
  scheduler = Schedule()
368
  scheduler.defaults(date, time, slot_length)
369
+ scheduler.schedule_slots(csv_path)
370
+
371
+ # Create user records in database
372
+ create_user(scheduler)
373
+
374
+ # Send email invitations
375
  scheduler.send_emails()
376
 
377
+ return jsonify({
378
+ "output": "Emails Sent Successfully",
379
+ "scheduled_count": len(scheduler.df)
380
+ })
381
+
382
+ except FileNotFoundError as e:
383
+ logging.error(f"File not found: {str(e)}")
384
+ return jsonify({"error": "CSV file not found", "message": str(e)}), 400
385
  except Exception as e:
386
  logging.error(f"Scheduling error: {str(e)}")
387
  return jsonify({"error": "Failed to schedule interviews", "message": str(e)}), 500