def __process_account(account, cfg): print "__processAccount(): ", account.getRef(), cfg # generate report item for later use reportItem = BingRewardsReportItem(account.getRef()) reportItem.accountType = account.accountType reportItem.accountLogin = account.accountLogin # generate headers for http requests (including spoofed agent string) httpHeaders = __generate_headers() # #$REFACTOR_HTTP$# #earn the rewards earnRewards(httpHeaders, reportItem, account.password, cfg) #if the earning was not successful, sleep and recurse if reportItem.error is not None: # we have to keep retry count; and other things, correct... print "__process_acount(): process failure, ", reportItem.retries, \ " attempts made" reportItem.retries += 1 reportItem.accountStatus = 1 else: reportItem.accountStatus = 0 return reportItem
def __run(config): report = list() doSleep = False for key, account in config.accounts.iteritems(): if account.disabled: continue # sleep between two accounts logins if doSleep: extra = config.general.betweenAccountsInterval + random.uniform( 0, config.general.betweenAccountsSalt) if verbose: print("\nPausing between accounts for {0} seconds".format( int(extra))) time.sleep(extra) reportItem = BingRewardsReportItem() reportItem.accountType = account.accountType reportItem.accountLogin = account.accountLogin agents = bingCommon.UserAgents.generate(account) httpHeaders = bingCommon.HEADERS httpHeaders["User-Agent"] = agents.pc __processAccount(config, httpHeaders, agents, reportItem, account.password) report.append(reportItem) doSleep = True # # trigger full report if needed # if showFullReport or totalPoints > 0 and len(report) > 1: print print "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= FINAL REPORT =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" print print " Account | Before | After | Earned | Lifetime | Retries " print "------------------------------+--------+--------+--------+------------+---------" for r in report: print " %-28s | %6d | %6d | %6d | %10d | %7d" % ( __stringifyAccount(r, 28), r.oldPoints, r.newPoints, r.pointsEarnedRetrying, r.lifetimeCredits, r.retries) print # # print footer # print "Total points earned: %d" % totalPoints print print "%s - script ended" % helpers.getLoggingTime() EventsProcessor.onScriptComplete(config)
def __run(config): report = list() doSleep = False for key, account in config.accounts.iteritems(): if account.disabled: continue # sleep between two accounts logins if doSleep: extra = config.general.betweenAccountsInterval + random.uniform(0, config.general.betweenAccountsSalt) if verbose: print("\nPausing between accounts for {0} seconds".format(int(extra))) time.sleep(extra) reportItem = BingRewardsReportItem() reportItem.accountType = account.accountType reportItem.accountLogin = account.accountLogin agents = bingCommon.UserAgents.generate(account) httpHeaders = bingCommon.HEADERS httpHeaders["User-Agent"] = agents.pc __processAccount(config, httpHeaders, agents, reportItem, account.password) report.append(reportItem) doSleep = True # # trigger full report if needed # if showFullReport or totalPoints > 0 and len(report) > 1: print print "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= FINAL REPORT =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" print print " Account | Before | After | Earned | Lifetime | Retries " print "------------------------------+--------+--------+--------+------------+---------" for r in report: print " %-28s | %6d | %6d | %6d | %10d | %7d" % (__stringifyAccount(r, 28), r.oldPoints, r.newPoints, r.pointsEarnedRetrying, r.lifetimeCredits, r.retries) print # # print footer # print "Total points earned: %d" % totalPoints print print "%s - script ended" % helpers.getLoggingTime() EventsProcessor.onScriptComplete(config)
def __run(config): report = list() accountIndex = 0 for key, account in config.accounts.iteritems(): if account.disabled: continue # sleep between two accounts logins if accountIndex > 0: isFirstAccount = False extra = config.general.betweenAccountsInterval + random.uniform(0, config.general.betweenAccountsSalt) time.sleep(extra) reportItem = BingRewardsReportItem() reportItem.accountType = account.accountType reportItem.accountLogin = account.accountLogin __processAccount(config, reportItem, account.password) report.append(reportItem) accountIndex += 1 EventsProcessor.onScriptComplete(config) # # trigger full report if needed # if showFullReport or totalPoints > 0 and len(report) > 1: print print " -=-=-=-=-=-=-=-=-=-=--=-=- FULL REPORT -=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=" print print " Account | Before | After | Earned | Retries | Lifetime Credits" print "---------------------------+--------+--------+--------+---------+-----------------" for r in report: print " %25s | %6d | %6d | %6d | %7d | %16d" % (__stringifyAccount(r, 25), r.oldPoints, r.newPoints, r.pointsEarnedRetrying, r.retries, r.lifetimeCredits) print # # print footer # print "Total points earned: %d" % totalPoints print print "%s - script ended" % helpers.getLoggingTime()
def __processAccountUserAgent(config, account, userAgents, doSleep): # sleep between two accounts logins if doSleep: extra = config.general.betweenAccountsInterval + random.uniform(0, config.general.betweenAccountsSalt) time.sleep(extra) reportItem = BingRewardsReportItem() reportItem.accountType = account.accountType reportItem.accountLogin = account.accountLogin httpHeaders = bingCommon.HEADERS httpHeaders["User-Agent"] = userAgents[ random.randint(0, len(userAgents) - 1) ] __processAccount(config, httpHeaders, reportItem, account.password) return reportItem
def __processAccountUserAgent(config, account, userAgents, doSleep): # sleep between two accounts logins if doSleep: extra = config.general.betweenAccountsInterval + random.uniform(0, config.general.betweenAccountsSalt) time.sleep(extra) reportItem = BingRewardsReportItem() reportItem.accountType = account.accountType reportItem.accountLogin = account.accountLogin agents = bingCommon.UserAgents.generate() httpHeaders = bingCommon.HEADERS httpHeaders["User-Agent"] = userAgents[ random.randint(0, len(userAgents) - 1) ] __processAccount(config, httpHeaders, agents, reportItem, account.password) return reportItem
def __processAccountUserAgent(config, account, userAgents, doSleep): # sleep between two accounts logins if doSleep: extra = config.general.betweenAccountsInterval + random.uniform(0, config.general.betweenAccountsSalt) if verbose: print print("Pausing between accounts for {0} seconds".format(int(extra))) time.sleep(extra) reportItem = BingRewardsReportItem() reportItem.accountType = account.accountType reportItem.accountLogin = account.accountLogin agents = bingCommon.UserAgents.generate(account) httpHeaders = bingCommon.HEADERS httpHeaders["User-Agent"] = agents.pc __processAccount(config, httpHeaders, agents, reportItem, account.password) return reportItem
def test_config(self): """ test config module :return: """ configobj = Config() self.assertIsNotNone(configobj, "should return class") self.assertIsNotNone(Config.General(), "should return class") self.assertIsNotNone(ConfigError("ok"), "should return exception") self.assertIsNotNone(Config.Proxy(), "should return class") self.assertIsNotNone(Config.EventAccount(), "should return class") self.assertIsNotNone(Config.Event.Notify(), "should return class") ifs = Config.Event.IfStatement() ifs.op = lambda x, y: x ifs.lhs = lambda x: x ifs.rhs = "b" self.assertIsNotNone(str(ifs), "should return class") self.assertRaisesRegexp(ValueError, "None", ifs.evaluate, None) self.assertRaisesRegexp(TypeError, "is not of", ifs.evaluate, []) self.assertIsNotNone(ifs.evaluate(BingRewardsReportItem())) spec = Config.Event.Specifier() self.assertIsNotNone(spec, "should return class") self.assertRaisesRegexp(ValueError, "is None", spec.evaluate, None, BingRewardsReportItem()) self.assertRaisesRegexp(TypeError, "list", spec.evaluate, [], BingRewardsReportItem()) self.assertRaisesRegexp(ValueError, "is None", spec.evaluate, [], None) self.assertRaisesRegexp(TypeError, "not of BingRewardsReportItem type", spec.evaluate, [], self.config) self.assertIsNotNone(spec.evaluate("%a", BingRewardsReportItem()), "should return string") dist = os.path.join(os.path.dirname(__file__), "..", "config.xml") self.assertIsNone(configobj.parseFromFile(dist), "should be none") self.assertRaisesRegexp(ValueError, "_configFile_ is None", configobj.parseFromFile, None) self.assertRaisesRegexp(ValueError, "is None", self.config.parseFromString, None) self.assertRaisesRegexp(ConfigError, "Invalid subnode", configobj.parseFromString, InvalidXML) self.assertRaisesRegexp(ConfigError, "is not found", configobj.parseFromString, LOGINXML) self.assertRaisesRegexp(ConfigError, "is not found", configobj.parseFromString, PWDXML) self.assertRaisesRegexp(ConfigError, "should be either set", self.config.parseFromString, PROXYLOGINXML) self.assertRaisesRegexp(KeyError, "_specifier_ is not", validateSpecifier, "%not") self.assertRaisesRegexp(ConfigError, "Invalid subnode", self.config.parseFromString, FBXML)
def test_event(self): """ test event :return: """ self.assertIsNone(EventsProcessor.onScriptFailure(self.config, Exception()), "should be none") self.assertIsNone(EventsProcessor.onScriptComplete(self.config), "should be none") self.assertRaisesRegexp(ConfigError, "not found", self.config.parseFromString, EVENT) self.config.parseFromString(EVENTLESS) self.assertRaisesRegexp(Exception, ".*", EventsProcessor.onScriptFailure, self.config, Exception()) self.assertIsNone(EventsProcessor.onScriptComplete(self.config), "should be none") ep = EventsProcessor(self.config, BingRewardsReportItem()) self.assertIsNotNone(ep.processReportItem(), "should not be none and be done")
def processAccount(config): bp = BingRewardsReportItem() return main.__processAccount(config, None, None, bp, "")