mytakedotorg/us-presidential-debates

Biden Trump round 2 breaks our naming conventions

Opened this issue · 0 comments

Lol, classic database schema problem. Our enforced naming convention is:

  • {LastNameAlphabetically1}-{LastNameAlphabetically2}-{number}-of-{count}.
  • e.g. biden-trump-1-of-2

But of course, this year there are only two debates scheduled, so this year's first debate would have the exact same slug as last year's. We enforce this naming convention like so:

videoJson { meta ->
// enforce that every fact has a title like "1 of 2"
def matcher = meta.fact.title =~ /\((\d) of (\d)\)/
assert(matcher.find())
// find the last names of the candidates, sort them, and join with ', '
String lastNames = meta.speakers.stream()
.filter({ speaker -> speaker.role.contains("for President") })
.map({ speaker ->
int lastSpace = speaker.fullName.lastIndexOf(' ')
return speaker.fullName.substring(lastSpace + 1)
})
.sorted().collect(java.util.stream.Collectors.joining(", "))
// combine the names and titles
meta.fact.title = lastNames + " (" + matcher.group(1) + " of " + matcher.group(2) + ")"
}

  • In #13 I worked around this by making it 2024-biden-trump-1-of-2, and turning off the validation logic above for anything in 2024. Probably someday we should rename the other debates to have a yyyy- in front, but we'll need perfect redirects.