Example #1
0
def getWeibo():
    weibo = Weibo()
    try:
        INFO('check weibo')
        global weibo_id_array
        global firstcheck_weibo
        # 初次启动记录前十条微博id
        if firstcheck_weibo is True:
            INFO('first check weibo')
            weibo_id_array = weibo.IdArray
            firstcheck_weibo = False
        if firstcheck_weibo is False:
            # 取最新的前三条微博
            for idcount in range(0, 3):
                # 广告位微博id为0,忽略
                if int(weibo.IdArray[idcount]) == 0:
                    continue
                # 微博id不在记录的id列表里,判断为新微博
                if weibo.IdArray[idcount] not in weibo_id_array:
                    msg = []
                    # 将id计入id列表
                    weibo_id_array.append(weibo.IdArray[idcount])
                    # 检查新微博是否是转发
                    if weibo.checkRetweet(idcount):
                        msg.append(
                            {
                                'type': 'text',
                                'data': {'text': '小偶像刚刚转发了一条微博:\n'}})
                        msg.append(
                            {
                                'type': 'text',
                                'data': {'text': '%s\n' % weibo.getRetweetWeibo(idcount)}})
                    # 原创微博
                    else:
                        msg.append(
                            {
                                'type': 'text',
                                'data': {'text': '小偶像刚刚发了一条新微博:\n'}})
                        msg.append(
                            {
                                'type': 'text',
                                'data': {'text': '%s\n' % weibo.getWeibo(idcount)}})
                        # 检查原创微博是否带图
                        if weibo.checkPic(idcount):
                            # 只取第一张图,pro可以直接发图,air则无
                            msg.append(
                                {
                                    'type': 'image',
                                    'data': {'file': '%s' % weibo.getPic(idcount)[0]}})
                            # 播报图的总数
                            if len(weibo.getPic(idcount)) > 1:
                                msg.append(
                                    {
                                        'type': 'text',
                                        'data': {'text': '\n(一共有%d张图喔)\n' % len(weibo.getPic(idcount))}})
                    msg.append(
                        {
                            'type': 'text',
                            'data': {'text': '传送门:%s' % weibo.getScheme(idcount)}})
                    for grpid in groupid():
                        bot.send_group_msg_async(
                            group_id=grpid, message=msg, auto_escape=False)
                        time.sleep(0.5)
                    # print(msg)
    except Exception as e:
        WARN('error when getWeibo', e)
    finally:
        INFO('weibo check completed')
Example #2
0
def getWeibo(i):
    contrainerID = i["contrainerID"]
    weibo = Weibo(contrainerID)
    weiboID = i["weiboID"]
    print(f"正在扫描 {weiboID}")
    try:
        # 初次启动记录前十条微博id
        if first_check_dict[contrainerID] is True:
            weibo_id_array = weibo.IdArray
            weibo_id_dict[contrainerID] = weibo_id_array
            first_check_dict[contrainerID] = False

        if first_check_dict[contrainerID] is False:
            # 取最新的前三条微博
            for idcount in range(0, 3):
                # 广告位微博id为0,忽略
                if int(weibo.IdArray[idcount]) == 0:
                    continue
                # 微博id不在记录的id列表里,判断为新微博
                if weibo.IdArray[idcount] not in weibo_id_dict[contrainerID]:
                    # 将id计入id列表
                    weibo_id_dict[contrainerID].append(weibo.IdArray[idcount])

                    # 检查新微博是否是转发
                    if weibo.checkRetweet(idcount):
                        print("[INFO] IGNORE REPOST TEXT")
                    else:
                        text = weibo.getWeibo(idcount)
                        url = weibo.getScheme(idcount)

                        tag = True

                        for word in i['keyword']:
                            if word not in text:
                                tag = False

                        if tag is True:
                            print("FIND NEW MESSAGE")
                            if i['shieldingWords'] == "":
                                title = f"{weiboID} 微博更新提醒"
                                mail_msg = text + "\n" + url
                                send(mail_msg, title)

                            if i['shieldingWords'] != "" and i[
                                    'shieldingWords'] not in text:
                                title = f"{weiboID} 微博更新提醒"
                                mail_msg = text + "\n" + url
                                send(mail_msg, title)
                            else:
                                print("[INFO] FIND SHIELDINGWORDS,")

                        else:
                            print("[INFO] TEXT DON'T MATCH")

                    time.sleep(0.5)

                else:
                    pass

    except Exception as e:
        print('[ERROE] GET WEIBO FAILED', e)
    finally:
        pass