Ejemplo n.º 1
0
def insert_jd_comments(comment_list: list, shop: Shop):
    for comment in comment_list:
        color, ram, rom = parse_mi10_product_info(comment['productColor'],
                                                  comment['productSize'])
        new_comment, created = Comment.get_or_create(
            source=shop.source,
            is_official=shop.is_official,
            comment_id='JD' + str(comment['id']),
            create_time=comment['creationTime'],
            content=comment['content'],
            star=comment['score'],
            order_time=comment['referenceTime'],
            order_days=comment['days'],
            product_color=color,
            product_ram=ram,
            product_rom=rom)
        if created is True:
            if 'afterUserComment' in comment:
                after_comment = comment['afterUserComment']
                new_comment.after_time = after_comment['created']
                new_comment.after_content = after_comment['content']
                new_comment.after_days = comment['afterDays']
            if comment['userClient'] == 4:
                new_comment.user_device = 'Android'
            elif comment['userClient'] == 2:
                new_comment.user_device = 'iOS'
            else:
                new_comment.user_device = 'other'
            new_comment.save()
def insert_youpin_comments(comment_list: list, shop: Shop):
    for comment in comment_list:
        if comment['comment_source'] == 'mishop':
            proper_source = '小米商城'
        else:
            proper_source = '小米有品'
        try:
            mi_sku = MiSku.get_by_id(str(comment['pid']))
        except MiSku.DoesNotExist:
            print('---此条评论对应的SKU不存在---')
            continue
        Comment.get_or_create(
            source=proper_source,
            is_official=shop.is_official,
            comment_id='MI' + str(comment['comment_id']),
            create_time=parse_timestamp_13bit(comment['ctime']),
            content=comment['text'],
            star=0,  # comment['score']
            product_color=mi_sku.product_color,
            product_ram=mi_sku.product_ram,
            product_rom=mi_sku.product_rom)
Ejemplo n.º 3
0
def insert_sn_comments(comment_list: list, shop: Shop):
    for comment in comment_list:
        try:
            commodity_info = comment['commodityInfo']
            color, ram, rom = parse_mi10_product_info(
                commodity_info['charaterDesc1'],
                commodity_info['charaterDesc2'])
        except (AttributeError, KeyError):
            print('---有一条评论对应的产品信息不规范, 跳过此条评论---')
            continue
        new_comment, created = Comment.get_or_create(
            source=shop.source,
            is_official=shop.is_official,
            comment_id='SN' + str(comment['commodityReviewId']),
            create_time=comment['publishTime'],
            content=comment['content'],
            star=comment['qualityStar'],
            product_color=color,
            product_ram=ram,
            product_rom=rom)
        if created is True:
            if comment['againFlag'] is True:
                after_comment = comment['againReview']
                new_comment.after_time = after_comment['publishTime']
                new_comment.after_content = after_comment['againContent']
                after_days_str = after_comment['publishTimeStr']
                if after_days_str == '当天追加':
                    after_days_num = 0
                else:
                    after_days_num = int(
                        re.match(r'^\d+', after_days_str).group())
                new_comment.after_days = after_days_num
            if comment['sourceSystem'] == 'android':
                new_comment.user_device = 'Android'
            elif comment['sourceSystem'] == 'ios':
                new_comment.user_device = 'iOS'
            else:
                new_comment.user_device = 'other'
            new_comment.save()