Skip to content

Instantly share code, notes, and snippets.

@hernantz
Created November 24, 2019 22:33
Show Gist options
  • Save hernantz/ca79890b9b212c6df45e615d94320f6e to your computer and use it in GitHub Desktop.
Save hernantz/ca79890b9b212c6df45e615d94320f6e to your computer and use it in GitHub Desktop.
Real world ifs and elses
def extract_timestamp(self):
record = self.get_parsed_record()
timestamp = record.get('timestamp')
if timestamp is None:
return None
if isinstance(timestamp, datetime):
return timestamp
return dateutil.parser.parse(record['timestamp'])
def get_parsed_record(self):
record = self.record
event_name = self.event_name
if event_name in (SasEvents.KNOWLEDGE_COMPONENT_MODEL,
SasEvents.KCM_UPDATE):
parsed_record = record
elif event_name == CeEvents.QUESTION_PART_ATTEMPT:
require_kcm = 'knowledge_component_model' in record
parsed_record = qpa.parse_question_part_attempt(
record, require_kcm=require_kcm)
elif event_name == SasEvents.TUNING_STATUS_CHANGED:
parsed_record = record
else:
parsed_record = record
return parsed_record
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment