def parse_datetime(dt_string):
"""
Attempts to parse a datetime string with any one of the datetime formats that we
expect from Pearson
Args:
dt_string (str): datetime string to be parsed
Returns:
datetime.datetime: parsed datetime
Raises:
UnparsableRowException:
Thrown if the datetime string cannot be parsed with any of the accepted formats
"""
for dt_format in PEARSON_DATETIME_FORMATS:
try:
return datetime.strptime(dt_string, dt_format).replace(tzinfo=pytz.UTC)
except ValueError:
pass
raise UnparsableRowException('Unparsable datetime: {}'.format(dt_string))
评论列表
文章目录