I am storing the dates of Presidential speeches and each speech's respective filename
in a dictionary. The speeches
object looks like this:
[<a href="/president/obama/speeches/speech-4427">Acceptance Speech at the Democratic National Convention (August 28, 2008)</a>,
<a href="/president/obama/speeches/speech-4424">Remarks on Election Night (November 4, 2008)</a>,...]
And end_link
looks like:
['/president/obama/speeches/speech-4427', '/president/obama/speeches/speech-4424',...]
Here's my code:
date_dict = {}
for speech in speeches:
text = speech.get_text(strip=True)
date = text[text.index("(") + 1:text.rindex(")")]
end_link = [tag.get('href') for tag in speeches if tag.get('href') is not None]
for x in end_link:
splitlink = x.split("/")
president = splitlink[2]
speech_num = splitlink[4]
filename = "{0}_{1}".format(president,speech_num)
if 2 == 2:
f = date_dict['{0} {1}'.format(filename,date)]
I get the proper date output (e.g. August 15, 1999
) and filename
is fine. Now, I'm just trying to join the two and am getting the following error:
date_dict['{0} {1}'.format(filename,date)]
KeyError: 'obama_speech-4427 August 28, 2008'
I don't really know where to go from here.