示例#1
0
def earnRewards(config, httpHeaders, userAgents, reportItem, password):
    """Earns Bing! reward points and populates reportItem"""
    noException = False
    try:
        if reportItem is None: raise ValueError("reportItem is None")
        if reportItem.accountType is None:
            raise ValueError("reportItem.accountType is None")
        if reportItem.accountLogin is None:
            raise ValueError("reportItem.accountLogin is None")
        if password is None: raise ValueError("password is None")

        del reportItem.error
        reportItem.error = None
        reportItem.pointsEarned = 0

        bingRewards = BingRewards(httpHeaders, userAgents, config)
        bingAuth = BingAuth(httpHeaders, bingRewards.opener)
        bingAuth.authenticate(reportItem.accountType, reportItem.accountLogin,
                              password)
        reportItem.oldPoints = bingRewards.getRewardsPoints()
        rewards = bfp.parseFlyoutPage(bingRewards.requestFlyoutPage(),
                                      bingCommon.BING_URL)

        if verbose:
            bingRewards.printRewards(rewards)
        print("%s - %s" % (reportItem.accountType, reportItem.accountLogin))
        results = bingRewards.process(rewards, verbose)

        if verbose:
            print
            print "-" * 80
            print

        bingRewards.printResults(results, verbose)

        reportItem.newPoints = bingRewards.getRewardsPoints()
        reportItem.lifetimeCredits = bingRewards.getLifetimeCredits()
        reportItem.pointsEarned = reportItem.newPoints - reportItem.oldPoints
        reportItem.pointsEarnedRetrying += reportItem.pointsEarned
        print
        print "%s - %s" % (reportItem.accountType, reportItem.accountLogin)
        print
        print "Points before:    %6d" % reportItem.oldPoints
        print "Points after:     %6d" % reportItem.newPoints
        print "Points earned:    %6d" % reportItem.pointsEarned
        print "Lifetime Credits: %6d" % reportItem.lifetimeCredits

        print
        print "-" * 80

        noException = True

    except AuthenticationError, e:
        reportItem.error = e
        print "AuthenticationError:\n%s" % e
示例#2
0
def earnRewards(config, httpHeaders, userAgents, reportItem, password):
    """Earns Bing! reward points and populates reportItem"""
    noException = False
    try:
        if reportItem is None: raise ValueError("reportItem is None")
        if reportItem.accountType is None: raise ValueError("reportItem.accountType is None")
        if reportItem.accountLogin is None: raise ValueError("reportItem.accountLogin is None")
        if password is None: raise ValueError("password is None")

        del reportItem.error
        reportItem.error = None
        reportItem.pointsEarned = 0

        bingRewards = BingRewards(httpHeaders, userAgents, config)
        bingAuth    = BingAuth(httpHeaders, bingRewards.opener)
        bingAuth.authenticate(reportItem.accountType, reportItem.accountLogin, password)
        reportItem.oldPoints = bingRewards.getRewardsPoints()
        rewards = bfp.parseFlyoutPage(bingRewards.requestFlyoutPage(), bingCommon.BING_URL)

        if verbose:
            bingRewards.printRewards(rewards)
        print ("%s - %s" % (reportItem.accountType, reportItem.accountLogin))
        results = bingRewards.process(rewards, verbose)

        if verbose:
            print
            print "-" * 80
            print

        bingRewards.printResults(results, verbose)

        reportItem.newPoints = bingRewards.getRewardsPoints()
        reportItem.lifetimeCredits = bingRewards.getLifetimeCredits()
        reportItem.pointsEarned = reportItem.newPoints - reportItem.oldPoints
        reportItem.pointsEarnedRetrying += reportItem.pointsEarned
        print
        print "%s - %s" % (reportItem.accountType, reportItem.accountLogin)
        print
        print "Points before:    %6d" % reportItem.oldPoints
        print "Points after:     %6d" % reportItem.newPoints
        print "Points earned:    %6d" % reportItem.pointsEarned
        print "Lifetime Credits: %6d" % reportItem.lifetimeCredits

        print
        print "-" * 80

        noException = True

    except AuthenticationError, e:
        reportItem.error = e
        print "AuthenticationError:\n%s" % e
示例#3
0
def earnRewards(authType, login, password):
    """Earns Bing! reward points and returnes how many points has been earned"""
    pointsEarned = 0
    noException = False
    try:
        if authType is None: raise ValueError("authType is None")
        if login is None: raise ValueError("login is None")
        if password is None: raise ValueError("password is None")

        bingRewards = BingRewards()
        bingAuth    = BingAuth(bingRewards.opener)
        bingAuth.authenticate(authType, login, password)
        points  = bingRewards.getRewardsPoints()
        rewards = bfp.parseFlyoutPage(bingRewards.requestFlyoutPage(), bingCommon.BING_URL)

        if verbose:
            bingRewards.printRewards(rewards)
        results = bingRewards.process(rewards)

        if verbose:
            print
            print "-" * 80
            print

        bingRewards.printResults(results, verbose)

        newPoints = bingRewards.getRewardsPoints()
        lifetimeCredits = bingRewards.getLifetimeCredits()
        pointsEarned = newPoints - points
        print
        print "%s - %s" % (authType, login)
        print
        print "Points before:    %6d" % points
        print "Points after:     %6d" % newPoints
        print "Points earned:    %6d" % pointsEarned
        print "Lifetime Credits: %6d" % lifetimeCredits

        print
        print "-" * 80

        noException = True

    except AuthenticationError, e:
        print "AuthenticationError:\n%s" % e
示例#4
0
    def _rewards_hit(self, classobj, helpmock):
        """
        test rewards object
        :return:
        """
        self.config.proxy = False
        reward = BingRewards(bingCommon.HEADERS, "", self.config)

        page = '"WindowsLiveId":""     "WindowsLiveId":"" '
        page += 'action="0" value="0" '
        page += 'value= "0" NAP value="0" '
        page += 'ANON value="0" '
        page += 'id="t" value="0" '
        page += '<div> 999 livetime points</div> '

        helpmock.return_value = page

        # if not login should have not found error for url
        self.assertIsNotNone(reward.getLifetimeCredits, "Should return int")

        page = "t.innerHTML='100'"
        helpmock.return_value = page
        self.assertIsNotNone(reward.getRewardsPoints(), "should not be None")
        self.assertRaisesRegexp(TypeError, "not an instance", reward.process, None, True)

        # NONE case
        newbfp = classobj
        newbfp.tp = None
        rewards = [newbfp]
        self.assertIsNotNone(reward.process(rewards, True), "handle not none")

        # HIT case
        newbfp.tp = mock.Mock()
        newbfp.tp = [0, 1, 2, 3, bfp.RewardV1.Type.Action.HIT]

        # SEARCH case
        newbfp.tp = mock.Mock()
        newbfp.tp = [0, 1, 2, 3, bfp.RewardV1.Type.Action.SEARCH]
        newbfp.progressCurrent = 100
        rewards = [newbfp]
        self.assertIsNotNone(reward.process(rewards, True), "should return res")

        self.assertRaisesRegexp(TypeError, "not an instance", reward.printResults, None, True)

        result = mock.Mock()
        result.action = bfp.RewardV1.Type.Action.SEARCH
        result.isError = True
        result.o = newbfp
        result.message = "done"
        newbfp.progressCurrent = 1
        newbfp.progressMax = 100
        newbfp.url = "http:0.0.0.0"
        self.assertIsNone(reward.printResults([result], True), "should return None")
        self.assertRaisesRegexp(TypeError, "rewards is not", reward.printRewards, None)
        rewards[0].isDone = True
        self.assertIsNone(reward.printRewards(rewards), "should return None")

        self.assertRaisesRegexp(TypeError, "reward is not", reward.RewardResult, None)
        self.assertIsNotNone(reward.RewardResult(newbfp), "should return class")

        proxy = mock.Mock()
        proxy.login = True
        proxy.password = "******"
        proxy.url = "http://127.0.0.1"
        proxy.protocols = "http"
        self.config.proxy = proxy
        self.assertIsNotNone(BingRewards(bingCommon.HEADERS, "", self.config), "should return class")

        proxy.login = False
        self.config.proxy = proxy
        self.assertIsNotNone(BingRewards(bingCommon.HEADERS, "", self.config), "should return class")

        self.assertRaisesRegexp(ConfigError, "not found", self.config.parseFromString, PROTXML)
        self.assertRaisesRegexp(ConfigError, "not found", self.config.parseFromString, URLXML)
示例#5
0
def earnRewards(config, httpHeaders, userAgents, reportItem, password):
    """Earns Bing! reward points and populates reportItem"""
    noException = False
    try:
        if reportItem is None: raise ValueError("reportItem is None")
        if reportItem.accountType is None: raise ValueError("reportItem.accountType is None")
        if reportItem.accountLogin is None: raise ValueError("reportItem.accountLogin is None")
        if password is None: raise ValueError("password is None")

        del reportItem.error
        reportItem.error = None
        reportItem.pointsEarned = 0

        bingRewards = BingRewards(httpHeaders, userAgents, config)
        bingAuth    = BingAuth(httpHeaders, bingRewards.opener)
        bingAuth.authenticate(reportItem.accountType, reportItem.accountLogin, password)
        reportItem.oldPoints = bingRewards.getRewardsPoints()
        rewards = bfp.parseFlyoutPage(bingRewards.requestFlyoutPage(), bingCommon.BING_URL)

        if verbose:
            bingRewards.printRewards(rewards)
        results = bingRewards.process(rewards)
        
        if verbose:
            print
            print ("-" * 80)
            print

        bingRewards.printResults(results, verbose)

        reportItem.newPoints = bingRewards.getRewardsPoints()
        reportItem.lifetimeCredits = bingRewards.getLifetimeCredits()
        reportItem.pointsEarned = reportItem.newPoints - reportItem.oldPoints
        reportItem.pointsEarnedRetrying += reportItem.pointsEarned
        print
        print ("%s - %s" % (reportItem.accountType, reportItem.accountLogin))
        print
        print ("Points before:    %6d" % reportItem.oldPoints)
        print ("Points after:     %6d" % reportItem.newPoints)
        print ("Points earned:    %6d" % reportItem.pointsEarned)
        print ("Lifetime Credits: %6d" % reportItem.lifetimeCredits)

        print
        print ("-" * 80)

        noException = True

    except AuthenticationError as e:
        reportItem.error = e
        print ("AuthenticationError:\n%s" % e)

    except HTMLParser.HTMLParseError as e:
        reportItem.error = e
        print ("HTMLParserError: %s" % e)

    except urllib.request.HTTPError as e:
        reportItem.error = e
        print ("The server couldn't fulfill the request.")
        print ("Error code: ", e.code)

    except urllib.request.URLError as e:
        reportItem.error = e
        print ("Failed to reach the server.")
        print ("Reason: ", e.reason)

    except SocketError as e:
        if e.errno != errno.ECONNRESET:
            raise

        # see http://stackoverflow.com/a/20568874/2147244
        # for explanation of the problem

        reportItem.error = e
        print ("Connection reset by peer.")

    finally:
        if not noException:
            print
            print ("For: %s - %s" % (reportItem.accountType, reportItem.accountLogin))
            print
            print ("-" * 80)