Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions linkedin2username.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ def split_name(name):
Some people have funny names. We assume the most important names are:
first name, last name, and the name right before the last name (if they have one)
"""
parsed = re.split(' |-', name)
# Split on spaces and dashes (included repeated)
parsed = re.split(r'[\s-]+', name)

# Iterate and remove empty strings
parsed = [part for part in parsed if part]

# Discard people without at least a first and last name
if len(parsed) < 2:
Expand All @@ -160,6 +164,10 @@ def split_name(name):
else:
split_name = {'first': parsed[0], 'second': '', 'last': parsed[-1]}

# Final sanity check to not proceed without first and last name
if not split_name['first'] or not split_name['last']:
return None

return split_name

def f_last(self):
Expand Down Expand Up @@ -544,7 +552,7 @@ def find_employees(result):
# For some reason it's nested
for item_body in element.get('items', []):
# Info we want is all under 'entityResult'
entity = item_body['item']['entityResult']
entity = item_body.get('item', {}).get('entityResult', {})

# There's some useless entries we need to skip over
if not entity:
Expand All @@ -557,7 +565,8 @@ def find_employees(result):
if full_name[:3] == 'Dr ':
full_name = full_name[4:]

occupation = entity['primarySubtitle']['text']
# Some users are missing a primary subtitle
occupation = entity.get('primarySubtitle', {}).get('text', '') if entity.get('primarySubtitle') else ''

found_employees.append({'full_name': full_name, 'occupation': occupation})

Expand Down