Fix syntax errors in Python script, checking for API key environment variable