本文整理汇总了Python中bot.Bot.quit_browser方法的典型用法代码示例。如果您正苦于以下问题:Python Bot.quit_browser方法的具体用法?Python Bot.quit_browser怎么用?Python Bot.quit_browser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bot.Bot
的用法示例。
在下文中一共展示了Bot.quit_browser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: choosePlayers
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import quit_browser [as 别名]
#.........这里部分代码省略.........
if len(ignorePlayers) == 0: # for player selection rate logging
logEligiblePlayers = [player for player in eligiblePlayers]
if len(eligiblePlayers) == 0: # report as much and exit gracefully
__report_no_more_selections( fulldf=fulldf,
sN=kwargs['sN'],
vMN=kwargs['vMN'],
activeDate=kwargs['activeDate'] )
return 'noneLeft'
###### update each of the accounts #####
numIters = 0 # if we iterate too many times, exit gracefully
lenDF = len(df) # for keeping track of how much we have left
failedAccounts = [] # in case we fail to update some accounts
updatedAccounts = [] # to keep track accounts to log to file
while len(updatedAccounts) != lenDF:
## Who have we already updated?
updatedUsernames = [ account[0] for account in updatedAccounts]
## If we've run the loop "too many" times, exit out
if numIters > (2 * lenDF):
logFailedAccounts( df=df, updatedUsernames=updatedUsernames,
logger=logger )
break
## Update those accounts baby!
for dummyIndex, index, username, password, sN, vMN in df.itertuples():
# log ps -A, for debugging purposes
# with open( Filepath.get_log_file(kwargs['activeDate'],
# kwargs['sN'], kwargs['vMN']), "a") as f:
# f.write('\n\n\n')
# f.write('ITER: {} with u, p: {}, {}\n'.format(
# numIters, username, password))
# f.write('TIME: {}\n'.format(datetime.now().time()))
# f.flush()
# subprocess.call(['ps', '-A'], stdout=f)
# don't update the same account twice
if username in updatedUsernames:
continue
# try to update the account
numIters += 1
try:
# print update information
print "\n--> Iteration {} of {}".format(numIters, 2 * lenDF)
print "--> Choosing players for account {} of {}. U: {}".format(
len(updatedAccounts)+1, lenDF, username)
print "------> Accounts Done: {0}({1:.2f}%)".format(
len(updatedAccounts),
float(len(updatedAccounts))/float(lenDF) * 100)
# make the appropriate bot and update him
bot, p1, p2 = (None, None, None) # in case we throw an exception before they get assigned
bot = Bot(str(username), str(password), activeDate)
print "-->Succesfully created Bot"
p1, p2 = __distribute_eligible_players(
funcDict=funcDict, bot=bot, sN=kwargs['sN'],
eligiblePlayers=eligiblePlayers)
# this should never happen. We now allow it to happen, because
# of ('Yadier', 'Molina', 'stl') on 07-18-2014. He is a catcher
#, and catchers get days off man!. We have to trust that our code
# isn't accidentally overlooking dudes
# except NoPlayerFoundException as e:
# logError( str(username), str(password), p1, p2, e, logger)
# if bot:
# bot.quit_browser() # closes display as well, if necessary
# raise
# if the user interferes, exit
except KeyboardInterrupt:
if bot:
bot.quit_browser() # closes display as well, if necessary
raise
# sometimes unstable browsers raise exceptions. Just try again
except Exception as e:
exc_type = sys.exc_info()[0]
print "------> Failure: {}".format(exc_type)
print "------> Logging to file"
logError( str(username), str(password), p1, p2, e, logger )
if bot:
bot.quit_browser() # closes display as well, if necessary
continue
# If it worked, record as much and keep going!
else:
print "-----> Success!"
updatedAccounts.append((username, p1, p2))
## Update the accounts file to reflect the updates
# we use the dictionary variables instead of the one's we retrieved
# at the top of the function because sN and vMN take on new values
# in the while loop
log_updated_accounts( updatedAccounts, sN=kwargs['sN'],
vMN=kwargs['vMN'], activeDate=kwargs['activeDate'] )