Пример #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(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
Пример #3
0
    def test_query(self):
        """
        test google queryGenerator
        :return:
        """
        q = googleTrends.queryGenerator(1)
        q.br = None
        q.unusedQueries = set()
        self.assertIsNotNone(q.generateQueries(10, set()))

        self.assertRaisesRegexp(ValueError, "is not", wikipedia.queryGenerator, None)
        useragents = bingCommon.UserAgents().generate(self.config.accounts)

        # test with proxy
        b = BingRewards(bingCommon.HEADERS, useragents, self.config)
        self.config.login = None

        # test without proxy
        b = BingRewards(bingCommon.HEADERS, useragents, self.config)
        q = wikipedia.queryGenerator(b)
        q.br = None
        q.unusedQueries = set()
        self.assertIsNotNone(q.generateQueries(10, set()))
Пример #4
0
def earnRewards(httpHeaders, reportItem, password, config):
	print "earnRewards()"
	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")
		
		print "earnRewards, begining rewards"
		bingRewards = BingRewards(httpHeaders, config)
		print "calling bing auth ", bingRewards.opener
		bingAuth	= BingAuth(httpHeaders, bingRewards.opener)
		print "calling bingAuth.auth "
		bingAuth.authenticate(reportItem.accountType, reportItem.accountLogin, password)
		print "auth complete"
		reportItem.oldPoints = bingRewards.getRewardsPoints()
		print "old points: ", reportItem.oldPoints
		rewards = bfp.parseFlyoutPage(bingRewards.requestFlyoutPage(), bingCommon.BING_URL)
		print "parsed flyout page"
		print "bing rewards.process"
		results = bingRewards.process(rewards)
		
		print "bingrewards.printResults"
		bingRewards.printResults(results, True)

		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

	except AuthenticationError, e:
		reportItem.error = e
		print "AuthenticationError:\n%s" % e
Пример #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)
        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
Пример #6
0
    def test_rewards_search(self, helpmock, permock):
        """
        Search rewards string
        :param helpmock:
        :param permock:
        :return:
        """
        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> '
        page += "t.innerHTML='100'"
        page += '<div id="b_content">'
        page += '<div id="content">'
        page += 'IG:"100"'
        page += "http://www.bing.com/fd/ls/GLinkPing.aspx"

        helpmock.return_value = page

        useragents = bingCommon.UserAgents().generate(self.config.accounts)
        reward = BingRewards(bingCommon.HEADERS, useragents, self.config)
        newbfp = bfp.RewardV1()
        reward.RewardResult(newbfp)

        newbfp.progressCurrent = 1
        newbfp.progressMax = 100
        newbfp.description = "Up to 10 points today, 10 points per search"

        newbfp.isDone = False

        # SEARCH case, PC, Mobile, Earn
        for data in [
            newbfp.Type.SEARCH_MOBILE,
            newbfp.Type.SEARCH_PC,
            newbfp.Type.YOUR_GOAL,
            newbfp.Type.MAINTAIN_GOLD,
            newbfp.Type.REFER_A_FRIEND,
            newbfp.Type.SEND_A_TWEET,
            newbfp.Type.RE_EARNED_CREDITS,
            newbfp.Type.COMPLETED,
            newbfp.Type.SILVER_STATUS,
            newbfp.Type.INVITE_FRIENDS,
            newbfp.Type.EARN_MORE_POINTS,
            newbfp.Type.SEARCH_AND_EARN,
            newbfp.Type.THURSDAY_BONUS,
            newbfp.Type.RE_QUIZ]:
            newbfp.tp = data
            newbfp.url = "www.espn.com"

            newbfp.Type = bfp.RewardV1.Type.Action.SEARCH
            rewards = [newbfp]
            newbfp.isAchieved = lambda: data is False
            self.assertIsNotNone(reward.process(rewards, True), "should return res")

        newbfp.isDone = True
        self.assertIsNotNone(reward.process(rewards, True), "should return res")

        self.config.proxy = None
        BingRewards(bingCommon.HEADERS, useragents, self.config)
Пример #7
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)
Пример #8
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)