Skip to content

Commit

Permalink
Merge pull request #441 from unitedstates/441-social-media-prefer-exi…
Browse files Browse the repository at this point in the history
…sting

prefer existing social media over first found
  • Loading branch information
konklone committed Feb 25, 2017
2 parents 418bf6e + bb1088b commit 4f8f24d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions scripts/social_media.py
Expand Up @@ -433,7 +433,7 @@ def verify():

bioguide = entry['id']['bioguide']

candidate = candidate_for(bioguide)
candidate = candidate_for(bioguide, current)
if not candidate:
# if current is in whitelist, and none is on the page, that's okay
if current.lower() in whitelist[service]:
Expand Down Expand Up @@ -490,7 +490,12 @@ def clean():
print("Saving historical legislators...")
save_data(media, "legislators-social-media.yaml")

def candidate_for(bioguide):

def candidate_for(bioguide, current = None):
"""find the most likely candidate account from the URL.
If current is passed, the candidate will match it if found
otherwise, the first candidate match is returned
"""
url = current_bioguide[bioguide]["terms"][-1].get("url", None)
if not url:
if debug:
Expand All @@ -509,6 +514,10 @@ def candidate_for(bioguide):
matches = re.findall(regex, body, re.I)
if matches:
all_matches.extend(matches)

if not current == None and current in all_matches:
return current

if all_matches:
for candidate in all_matches:
passed = True
Expand Down

0 comments on commit 4f8f24d

Please sign in to comment.