Skip to content

Commit

Permalink
Add error handling when processing work experiences
Browse files Browse the repository at this point in the history
  • Loading branch information
shri committed Sep 5, 2024
1 parent ca968a4 commit da2c084
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/app/domain/people/controllers/persons.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,24 @@ async def create_person_from_url(
if get_domain_from_email(person_details.get("work_email", "")) == get_domain(company_db_obj.url):
work_email = person_details.get("work_email")

work_experiences = []
for work_ex in person_details.get("experience", []):
try:
work_experiences.append(
WorkExperience(
starts_at=datetime.strptime(work_ex.get("start_date"), "%Y-%m").date(),
title=work_ex.get("title", {}).get("name", "Unknown"),
company_name=work_ex.get("company", {}).get("name", "Unknown"),
company_url=work_ex.get("company", {}).get("website"),
company_linkedin_profile_url=work_ex.get("linkedin_url"),
ends_at=datetime.strptime(work_ex.get("end_date"), "%Y-%m").date()
if work_ex.get("end_date")
else None,
)
)
except Exception:
pass

# Add person
# TODO: Move this code into a provider specific code
obj = PersonCreate(
Expand All @@ -158,20 +176,7 @@ async def create_person_from_url(
work_email=work_email,
personal_numbers=person_details.get("personal_numbers", []),
birth_date=birth_date,
work_experiences=[
WorkExperience(
starts_at=datetime.strptime(work_ex.get("start_date"), "%Y-%m").date(),
title=work_ex.get("title", {}).get("name", "Unknown"),
company_name=work_ex.get("company", {}).get("name", "Unknown"),
company_url=work_ex.get("company", {}).get("website"),
company_linkedin_profile_url=work_ex.get("linkedin_url"),
ends_at=datetime.strptime(work_ex.get("end_date"), "%Y-%m").date()
if work_ex.get("end_date")
else None,
)
for work_ex in person_details.get("experience", [])
if work_ex.get("start_date") and work_ex.get("company", {})
],
work_experiences=work_experiences,
company_id=company_db_obj.id,
)
db_obj = await persons_service.upsert(obj.to_dict(), item_id=results[0].id if count > 0 else None)
Expand Down

0 comments on commit da2c084

Please sign in to comment.