def get_ordered_dict(data): """ 获取有序字典 :param data: :return: """ # 获取有序字典 ordered_dict = OrderedDict() tmp_ordered_day_list = [{ datetime_to_timestamp(date_parse(key)): key, } for key in data.keys()] # 已被正确排序的日期 ordered_day_list = sorted( tmp_ordered_day_list, key=lambda item: item.keys()) # pprint(ordered_day_list) for item_dict in ordered_day_list: item_dict_value = list(item_dict.values())[0] # print(item_dict_value) for key, value in data.items(): if key == item_dict_value: ordered_dict[key] = value else: continue return ordered_dict
def _get_comment_date(self, item) -> str: ''' 得到规范化的时间信息 :param comment_date: :return: str 格式: 2017-05-26 09:00:00 ''' comment_date = item.get('createTime', '') assert comment_date != '', '得到的comment_date为空str!请检查!' # self.lg.info(comment_date) # datetime.datetime(2019, 2, 25, 0, 0) comment_date = str(date_parse(target_date_str=comment_date)) return comment_date