File size: 1,667 Bytes
f499c12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5f277bb
f499c12
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import json
from pyairtable import Api
from dotenv import load_dotenv

load_dotenv()


def save_to_airtable(candidate_data: dict, job_role: str):
    """
    Saves the candidate data using the exact field names
    identified in image_95657f.png.
    """
    try:
        # Initialize the Airtable API client
        api = Api(os.getenv("AIRTABLE_API_KEY"))
        table = api.table(os.getenv("AIRTABLE_BASE_ID"), os.getenv("AIRTABLE_TABLE_NAME"))

        # Format the skills list into a single readable string
        skills_list = candidate_data.get("skills") or []
        skills_string = ", ".join(skills_list)

        links = candidate_data.get("links") or {}

        # Mapping to the exact names in your Airtable field list
        record = {
            "Full Name": candidate_data.get("full_name"),
            "Email": candidate_data.get("email"),
            "Experience": candidate_data.get("total_years_experience"),
            "Job Role": job_role,
            "Match Score": candidate_data.get("job_fit_score"),
            "Resume Summary": candidate_data.get("hr_summary"),
            "Key Skills": skills_string,
            "LinkedIn": links.get("linkedin"),
            "Portfolio": links.get("portfolio"),
            "CV Link": candidate_data.get("cv_url"),
            "Raw JSON": json.dumps(candidate_data, indent=2)
        }

        # Push the record to Airtable
        response = table.create(record)
        return response

    except Exception as e:
        # If this fails, the error message will help us identify
        # any remaining field name mismatches.
        raise ValueError(f"Airtable Sync Error: {str(e)}")