Example #1
0
def FollowMe(number, logger):
    followNum = 0
    for task in FollowMeTask.objects.filter(type=1, status=0)[:number * 2]:
        try:
            if followNum > number:
                break
            try:
                user = Access.objects.get(uid=task.uid)
            except:
                logger.error("not find access info for %d", task.uid)
                continue

            logger.debug("user %d" % user.uid)
            if user.version == 1:
                client = APIClientV1(BGApp.wdj_app_key, BGApp.wdj_app_secret,
                                     OAuthToken(user.data1, user.data2))
                try:
                    tuser = client.post.users__show(source=BGApp.wdj_app_key,
                                                    user_id=user.uid)
                except Exception, e:
                    print e
                    logger.debug(traceback.format_exc())
                    logger.debug("time out access token")
                    task.status = 2
                    task.save()
                    time.sleep(1)
                    continue
                client.post.friendships__create(source=BGApp.wdj_app_key,
                                                user_id=BGApp.dev_uid)
                task.status = 1
                task.save()
                followNum += 1
            elif user.version == 2:
                client = APIClientV2(BGApp.wdj_app_key, BGApp.wdj_app_secret)
                client.set_access_token(user.data1,
                                        time.time() + 90 * 24 * 3600)
                try:
                    tuser = client.get.users__show(uid=user.uid)
                except:
                    logger.debug(traceback.format_exc())
                    traceback.print_exc()
                    logger.debug("time out access token")
                    time.sleep(1)
                    task.status = 2
                    task.save()
                    continue
                followed = FriendShip.Follow(client, BGApp.dev_uid)
                task.status = 1
                followNum += 1
                task.save()
            else:
                logger.debug("bad user version %d", user.version)
                task.status = 2
                task.save()
                followNum += 1
                continue
            time.sleep(60)
Example #2
0
def get_user_info_v2(uid_, access_token_):
    weiboClientV2 = APIClientV2(app_key, app_secret)
    weiboClientV2.set_access_token(access_token_, time.time() + 90 * 24 * 3600)

    user = None

    try:
        user = weiboClientV2.get.users__show(access_token=access_token_,
                                             uid=uid_)
    except Exception, e:
        print e
Example #3
0
def unfollow_v2(access_token_, uid_):
    weiboClientV2 = APIClientV2(app_key, app_secret)
    weiboClientV2.set_access_token(access_token_, time.time() + 90 * 24 * 3600)

    successed = False

    try:
        ret = weiboClientV2.post.friendships__destroy(uid=uid_)
        successed = True
    except Exception, e:
        print e
Example #4
0
def is_follow_v2(access_token_, source_uid_, target_uid_):
    weiboClientV2 = APIClientV2(app_key, app_secret)
    weiboClientV2.set_access_token(access_token_, time.time() + 90 * 24 * 3600)

    followed = False

    try:
        ret = weiboClientV2.get.friendships__show(access_token=access_token_,
                                                  source_id=source_uid_,
                                                  target_id=target_uid_)
        followed = ret.source.following
    except Exception, e:
        print e
Example #5
0
if __name__ == '__main__':
    from Utils import *
    os.chdir(work_path)

    logger = InitLogger("follow_competitor", logging.DEBUG,
                        "../log/follow_competitor.log")
    try:
        if not CheckSingle(singleFilePath):
            sys.exit("another instance running")
        comsDb = Competitor.GetAllCompetitors()
        logger.debug("competitor len %d" % len(comsDb))
        comsWeb = copy.deepcopy(comsDb)
        todayMaxNum = 100
        todayOpNum = len(Operation.FetchSomeDayOps(Operation.FollowType, 0))
        logger.debug("current op number %d" % todayOpNum)
        client = APIClientV2(BGApp.app_key, BGApp.app_secret)
        client.set_access_token(BGApp.other_token,
                                time.time() + 90 * 24 * 3600)
        Competitor.GetNumbers(client, comsWeb, logger)
        for comDb in comsDb:
            for comWeb in comsWeb:
                if comDb.uid == comWeb.uid:
                    if comWeb.followers > comDb.followers:
                        num = comWeb.followers - comDb.followers
                        logger.debug("%d's followers increase %d" %
                                     (comWeb.uid, num))
                        if num > 1:
                            num = 1
                        followers = comWeb.GetFollowers(client, num)
                        for user in followers:
                            if todayOpNum < todayMaxNum: