当前位置: 首页>>代码示例>>Python>>正文


Python Record.forward方法代码示例

本文整理汇总了Python中record.Record.forward方法的典型用法代码示例。如果您正苦于以下问题:Python Record.forward方法的具体用法?Python Record.forward怎么用?Python Record.forward使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在record.Record的用法示例。


在下文中一共展示了Record.forward方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_records_from_html

# 需要导入模块: from record import Record [as 别名]
# 或者: from record.Record import forward [as 别名]
def get_records_from_html(html, page_num, poster_id=''):
    record_list = []
    parsed_html = bs4.BeautifulSoup(html, 'lxml')
    record_div_list = parsed_html.find_all(id=re.compile('M_.*'))  # list of the microblog records
    for record_div in record_div_list:
        record = Record()
        # get the poster_id
        record.poster_id = poster_id
        # a record conists of two child div, the first contains contents and the second contains time, reposts and so on
        record_child_div = list(record_div.children)
        # get the content
        record.content = record_child_div[0].select('[class="ctt"]')[0].get_text()

        # get the is_forwarded, like, forward, comment
        # is_forwarded
        record.is_forwarded = True if len(record_child_div) == 3 else False

        if len(record_child_div) >= 2:
            div1_text = record_child_div[1].get_text()
            pattern_like = re.compile(u'赞\[([0-9]+)\]')
            pattern_forward = re.compile(u'转发\[([0-9]+)\]')
            pattern_comment = re.compile(u'评论\[([0-9]+)\]')
            match_like = pattern_like.findall(div1_text)
            match_forward = pattern_forward.findall(div1_text)
            match_comment = pattern_comment.findall(div1_text)

            record.like = int(match_like[0])
            record.forward = int(match_forward[0])
            record.comment = int(match_comment[0])

        # get the time
        raw_record_time = record_child_div[-1].find_all("span", "ct", recursive=False)[-1].get_text()
        time_index = raw_record_time.find(u'来自')
        raw_record_time = raw_record_time[0:(time_index - 1)]
        logger.info('raw_record_time :' + str(raw_record_time))

        if u'前' in raw_record_time or u'今天' in raw_record_time:  # 今天
            record.time = datetime.date.today()
        elif u'月' in raw_record_time and u'日' in raw_record_time:  # 今年中的某一天
            # datetime不支持闰年
            if u'02月29日' in raw_record_time:
                logger.debug('02.29 Detected !')
                raw_record_time = raw_record_time.replace('29', '28')
                logger.info('Already replaced by 02.28 !')
            try:
                record_time = datetime.datetime.strptime(raw_record_time , u'%m月%d日 %H:%M')
            except:
                logger.error('Strptime Error this year ! ---- raw_record_time is: '+ str(raw_record_time))
                return
            record_time = record_time.replace(year=2017)
            record.time = record_time.date()
        else:  # 前面的年份
            try:
                record_time = datetime.datetime.strptime(raw_record_time, '%Y-%m-%d %H:%M:%S')
            except:
                logger.error('Strptime Error previous year ! ---- raw_record_time is: '+ str(raw_record_time))
                return
            record.time = record_time.date()
        record.time = str(record.time)
        record.hash = hashlib.sha1(str(record.content)).hexdigest()
        record.page_num = page_num

        record_list.append(record.__dict__)
        logger.info(str(record.__dict__))


    return record_list
开发者ID:SebastianElvis,项目名称:ElvisProjs,代码行数:69,代码来源:weibo_utils.py


注:本文中的record.Record.forward方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。