def combine_histories_and_messages(histories, smsMessages):
cmdSuccessStyle = 'class="commandSuccess"'
cmdErrorStyle = 'class="commandError"'
basicStyle = ''
from_zone = tz.tzutc()
to_zone = tz.tzlocal()
combinedList = []
for history in histories:
combinedList.append({"action": history.get('state'), "timestamp": history.get('changedAt'), "style": basicStyle})
for smsMessage in smsMessages:
style = cmdSuccessStyle if smsMessage.get('status').lower() == 'processed' else cmdErrorStyle
createdAt = smsMessage.get('createdAt').replace(tzinfo=from_zone)
combinedList.append({"action": smsMessage.get('body').lower(), "timestamp": createdAt.astimezone(to_zone), "style": style})
combinedList.sort(key=lambda c: c.get("timestamp"))
return combinedList
评论列表
文章目录