def getPlanetStatus(): debug = True xBanner = "html/body/h1" xPlanetStatus = "html/body/div[1]" planetStatus = {} if debug: print("Attempting to extract the owned planet status") # retrieve the current page currentPage = bnw.getPage() baseURL = ('/').join(currentPage.split('/')[:-1]) planetStatusPage = "{}/planet_report.php".format(baseURL) mainPage = "{}/main.php".format(baseURL) bnw.loadPage(planetStatusPage) time.sleep(2) bannerText = bnw.textFromElement(xBanner) if bannerText == "DONTEXIST": print("Unable to load planet status page") exit(1) if bannerText != "Planet Report: Status": print("Unexpected Banner Text: {}".format(bannerText)) exit(1) # retrieve the planet stats if debug: print("Retrieving planet stats") planetBlob = bnw.textFromElement(xPlanetStatus) if "You have no planets so far" in planetBlob: bnw.loadPage(mainPage) return planetStatus
def getSettings(baseURL): debug = True # xpaths # Key #1 # html/body/table[1]/tbody/tr[1]/td[1] # Value #1 # html/body/table[1]/tbody/tr[1]/td[2] # Key #2 # html/body/table[1]/tbody/tr[2]/td[1] # Value #2 # html/body/table[1]/tbody/tr[2]/td[2] # ... # Key # 27 # html/body/table[1]/tbody/tr[27]/td[1] # Value # 27 # html/body/table[1]/tbody/tr[27]/td[2] xBanner = "html/body/h1[3]" settingsPage = "http://{}/settings.php".format(baseURL) bnw.loadPage(settingsPage) time.sleep(2) bannerText = bnw.textFromElement(xBanner) if bannerText == "DONTEXIST": print("Unable to load the game global settings page") exit(1) elif not bannerText == "Game Settings": print("Unexpected banner text: {}, was looking for 'Game Settings'". format(bannerText)) exit(1) if debug: print("Game Settings page successfully loaded") gameSettings = {} for settingNumber in range(1, 28): keyXpath = "html/body/table[1]/tbody/tr[{}]/td[1]".format( settingNumber) valueXpath = "html/body/table[1]/tbody/tr[{}]/td[2]".format( settingNumber) keyText = bnw.textFromElement(keyXpath) valueText = bnw.textFromElement(valueXpath) keyText = keyText.strip() valueText = valueText.strip() if keyText == "DONTEXIST" or valueText == "DONTEXIST": print("Unable to retrieve the key value for settings #{}".format( settingNumber)) exit(1) # remove commas from numbers valueText = valueText.replace(',', '') gameSettings[keyText] = valueText if debug: print("DONE Parsing the settings page") return gameSettings
def currentMax(xpath): rawValue = bnw.textFromElement(xpath) if rawValue == "DONTEXIST": print("currentMax was passed a bad xpath") exit(1) rawList = rawValue.replace(',','').split('/') return (toNumber(rawList[0]), toNumber(rawList[1]))
def createPlayer(playerEmail, playerName, shipName, gameURL): debug = True # xpaths xEmailAddress = 'html/body/form/dl/dd[1]/input' xShipName = 'html/body/form/dl/dd[2]/input' xPlayerName = 'html/body/form/dl/dd[3]/input' xPageBanner = 'html/body/h1' xSubmitButton = 'html/body/form/div/input[1]' if debug: print("Attempting to load the new player entry page") newPlayerPage = 'http://{}/new.php'.format(gameURL) bnw.loadPage(newPlayerPage) bannerText = bnw.textFromElement(xPageBanner) if not bannerText == 'Create New Player': if debug: print('Unable to load the create new player page - bad URL?') return ['ERROR', 'Bad URL'] if not bnw.fillTextBox(xEmailAddress, playerEmail): if debug: print('Unable to fill in the new player email address') return ['ERROR', 'E-Mail XPath Error'] if not bnw.fillTextBox(xShipName, shipName): if debug: print('Unable to fill in the new player ship name') return ['ERROR', 'Ship Name XPath Error'] if not bnw.fillTextBox(xPlayerName, playerName): if debug: print('Unable to fill in the new player name') return ['ERROR', 'Player Name XPath Error'] if not bnw.clickButton(xSubmitButton): if debug: print('Unable to click the new player submit button') return ['ERROR', 'Submit Button Error'] time.sleep(3) bannerText = bnw.textFromElement(xPageBanner) if not bannerText == 'Create New Player Phase Two': if debug: print('Error entering new player info?') return ['ERROR', 'Bad Player Info'] print('Password must have been sent...')
def login(email, password, gameURL): debug = True # xpaths xEmail = ".//*[@id='email']" xPassword = "******" xBadLogin = "******" xLoginButton = "html/body/div[6]/form/div[2]/input" xTurnsLeft = "html/body/table[1]/tbody/tr[1]/td[1]/span" xInSector = "html/body/table[1]/tbody/tr[3]/td[1]/span" xFunds = "html/body/table[1]/tbody/tr[1]/td[1]/span" xScore = "html/body/table[1]/tbody/tr[1]/td[3]/span" xSectorType = "html/body/table[1]/tbody/tr[3]/td[3]/a" xSectorPort = "html/body/table[2]/tbody/tr/td[2]/div[1]" xSectorPort = "html/body/table[2]/tbody/tr/td[2]/div[1]/span" xPageBanner = "html/body/div[6]/h1" xWholePage = "html/body" if debug: print("Attempting to load the player login page") loginPage = 'http://{}'.format(gameURL) bnw.loadPage(loginPage) bannerText = bnw.textFromElement(xPageBanner) if not bannerText == 'Welcome to Blacknova Traders!': if debug: print('Unable to load the login page - bad URL?') return ['ERROR', 'Bad URL'] if not bnw.fillTextBox(xEmail, email): if debug: print('Unable to fill in the player email address') return ['ERROR', 'E-Mail XPath Error'] if not bnw.fillTextBox(xPassword, password): if debug: print('Unable to fill in the new player ship name') return ['ERROR', 'Ship Name XPath Error'] if not bnw.clickButton(xLoginButton): if debug: print('Unable to click the LOGIN button') return ['ERROR', 'LOGIN Button Error'] # Keep looping till either we log in, or get an error while True: if bnw.elementExists(xTurnsLeft): break if bnw.elementExists(xBadLogin): badText = bnw.textFromElement(xBadLogin) if badText == "Login Phase Two": if debug: print("Problem with the login credentials") wholePageText = bnw.textFromElement(xWholePage) if "The password you entered is incorrect" in wholePageText: return ['ERROR', 'Incorrect Password'] if "No Such Player" in wholePageText: return ['ERROR', "No Such Player"] time.sleep(1) print("Looks like we logged in!") return ("SUCCESS", "")
def specialPort(purchaseDict): specialText = "Special Port" genericText = "Trading Commodities" xBanner = "html/body/h1" xWholePage = "html/body" # cost of the tech, Quantity on hand, input box for purchasing more xGenesisTorps = [ "html/body/form/table[1]/tbody/tr[2]/td[2]", "html/body/form/table[1]/tbody/tr[2]/td[3]", "html/body/form/table[1]/tbody/tr[2]/td[5]/input" ] xSpaceBeacons = [ "html/body/form/table[1]/tbody/tr[3]/td[2]", "html/body/form/table[1]/tbody/tr[3]/td[3]", "html/body/form/table[1]/tbody/tr[3]/td[5]/input" ] xEmerWarpDev = [ "html/body/form/table[1]/tbody/tr[4]/td[2]", "html/body/form/table[1]/tbody/tr[4]/td[3]", "html/body/form/table[1]/tbody/tr[4]/td[5]/input" ] xWarpEditors = [ "html/body/form/table[1]/tbody/tr[5]/td[2]", "html/body/form/table[1]/tbody/tr[5]/td[3]", "html/body/form/table[1]/tbody/tr[5]/td[5]/input" ] xMineDeflectors = [ "html/body/form/table[1]/tbody/tr[7]/td[2]", "html/body/form/table[1]/tbody/tr[7]/td[3]", "html/body/form/table[1]/tbody/tr[7]/td[5]/input" ] xFighters = [ "html/body/form/table[2]/tbody/tr[2]/td[2]", "html/body/form/table[2]/tbody/tr[2]/td[3]", "html/body/form/table[2]/tbody/tr[2]/td[5]/input" ] xArmorPoints = [ "html/body/form/table[2]/tbody/tr[3]/td[2]", "html/body/form/table[2]/tbody/tr[3]/td[3]", "html/body/form/table[2]/tbody/tr[3]/td[5]/input" ] xEscapePod = [ "html/body/form/table[1]/tbody/tr[8]/td[2]", "html/body/form/table[1]/tbody/tr[8]/td[3]", "html/body/form/table[1]/tbody/tr[8]/td[5]/input" ] xFuelScoop = [ "html/body/form/table[1]/tbody/tr[9]/td[2]", "html/body/form/table[1]/tbody/tr[9]/td[3]", "html/body/form/table[1]/tbody/tr[9]/td[5]/input" ] xLastShipSeenDev = [ "html/body/form/table[1]/tbody/tr[10]/td[2]", "html/body/form/table[1]/tbody/tr[10]/td[3]", "html/body/form/table[1]/tbody/tr[10]/td[5]/input" ] xTorpedoes = [ "html/body/form/table[2]/tbody/tr[2]/td[7]", "html/body/form/table[2]/tbody/tr[2]/td[8]", "html/body/form/table[2]/tbody/tr[2]/td[10]/input" ] xColonists = [ "html/body/form/table[2]/tbody/tr[3]/td[6]", "html/body/form/table[2]/tbody/tr[3]/td[8]", "html/body/form/table[2]/tbody/tr[3]/td[10]/input" ] compList = [ "Hull", "Engines", "Power", "Computer", "Sensors", "Beam Weapons", "Armor", "Cloak", "Torpedo launchers", "Shields" ] xSelectors = {} # http://stackoverflow.com/questions/22171558/what-does-enumerate-mean for compoffset, compName in enumerate(compList, 2): xSelectors[ compName] = "html/body/form/table[1]/tbody/tr[{}]/td[9]/select".format( compoffset) xBuyButton = "html/body/form/table[3]/tbody/tr/td[1]/input" xCredits = "html/body/p[1]" xResultsBanner = "html/body/table/tbody/tr[1]/td/font/strong" xTotalCost = "html/body/table/tbody/tr[2]/td/strong/font" currentPage = bnw.getPage() baseURL = ('/').join(currentPage.split('/')[:-1]) portPage = "{}/port.php".format(baseURL) mainPage = "{}/main.php".format(baseURL) # load the page bnw.loadPage(portPage) if not bnw.elementExists(xBanner): allText = bnw.textFromElement(xWholePage) if "There is no port here" in allText: print("There is no port in this sector") bnw.load(mainPage) return ["ERROR", "NO PORT"] else: print("Unhandled Error #1 in specialPort") exit(1) bannerText = bnw.textFromElement(xBanner) if genericText in bannerText: print("This is not a special port") bnw.load(mainPage) return ["ERROR", "WRONG PORT"] if not bannerText == specialText: print("Unhandled Error #2 in specialPort") exit(1) # determine how many credits are available for spending textBlob = bnw.textFromElement(xCredits) # regex out the cost # You have 206,527,757 credits to spend. m = re.search("have\s+(.*)\s+credits", textBlob) if not m: print("Unable to regex the available credits!") exit(1) creditAvailable = int(m.group(1).replace(",", "")) print("Credits available: {}".format(creditAvailable)) # get the current tech levels currentTech = {} desiredTech = {} for compName in compList: if compName in purchaseDict: xpath = xSelectors[compName] currentTech[compName] = int(bnw.selectedValue(xpath)) desiredTech[compName] = purchaseDict[compName] print("Current {} Tech: {}, Desired Tech: {}".format( compName, currentTech[compName], desiredTech[compName])) if desiredTech[compName] != currentTech[compName]: if not bnw.selectDropDownNew(xSelectors[compName], desiredTech[compName]): print( "Unable to select the requested {} tech value".format( compName)) exit(1) print("Attempting to execute the purchase") if not bnw.clickButton(xBuyButton): print("Was unable to click the 'Buy' button") exit(1) time.sleep(2) if not bnw.elementExists(xResultsBanner): allText = bnw.textFromElement(xWholePage) m = re.search( "total cost is\s+(.*)\s+credits and you only have\s+(.*)\s+credits.", allText) if not m: print("Not a successful trade, and unable to determine why") exit(1) theCost = int(m.group(1).replace(",", "")) theCredits = int(m.group(2).replace(",", "")) notEnough = theCost - theCredits print("Short {} credits".format(notEnough)) return ["ERROR", "TOO EXPENSIVE"] resultBanner = bnw.textFromElement(xResultsBanner) if not resultBanner == "Results for this trade": print("Results banner not found") exit(1) # Cost : 2,500 Credits finalBlob = bnw.textFromElement(xTotalCost) if finalBlob == "DONTEXIST": print("Total cost not found") exit(1) m = re.search("Cost\s\:\s(.*)\sCredits", finalBlob) if not m: print("Unable to regex the final cost") exit(1) finalCost = int(m.group(1).replace(",", "")) print("final cost: {}".format(finalCost)) bnw.loadPage(mainPage) return ["SUCCESS", finalCost]
def changePasswd(currentPass, newPass): debug = True # xpaths xCurrentPass = "******" xNewPass = "******" xConfirmPass = "******" xSaveButton = "html/body/form/input" xBanner = "html/body/h1" xWholePage = "html/body" # retrieve the current page currentPage = bnw.getPage() baseURL = ('/').join(currentPage.split('/')[:-1]) print("baseURL: {}".format(baseURL)) optionPage = "{}/options.php".format(baseURL) print("optionPage: {}".format(optionPage)) bnw.loadPage(optionPage) time.sleep(2) bannerText = bnw.textFromElement(xBanner) if bannerText == "DONTEXIST": print("Unable to load the options page") exit(1) elif not bannerText == "Options": print("Unexpected banner text: {}, was looking for 'Options'".format( bannerText)) exit(1) if debug: print("Option page successfully loaded") print("Attempting to change the player password") if not bnw.fillTextBox(xCurrentPass, currentPass): if debug: print('Unable to fill in the player current password') return ['ERROR', 'Current Password XPath Error'] if not bnw.fillTextBox(xNewPass, newPass): if debug: print('Unable to fill in the player new password') return ['ERROR', 'New Password XPath Error'] if not bnw.fillTextBox(xConfirmPass, newPass): if debug: print('Unable to fill in the player confirm password') return ['ERROR', 'Confirm Password XPath Error'] if debug: print("Attempting to submit the changes") if not bnw.clickButton(xSaveButton): if debug: print('Unable to click the Save button') return ['ERROR', 'Save Button Error'] saved = False # determine if the update succeeded or not # have to examine the entire page text if bnw.elementExists(xWholePage): wholePageText = bnw.textFromElement(xWholePage) else: print("Was not able to extract all text from the option change") exit(1) if "Password changed." in wholePageText: print("Password has been successfully changed") return ["SUCCESS", ""] else: return ['ERROR', 'Could not change password']
def getStatus(): debug = False playerStatus = {} if debug: print('Querying turns left') turnsLeft = bnw.textFromElement(xTurnsLeft) if turnsLeft == "DONTEXIST": print("The turns remaining xpath is incorrect") exit(1) else: playerStatus['turnsLeft'] = int(turnsLeft.replace(',','')) if debug: print('Querying current sector') currentSector = bnw.textFromElement(xInSector) if currentSector == "DONTEXIST": print("The current sector xpath is incorrect") exit(1) else: playerStatus['currentSector'] = int(currentSector) if debug: print('Querying current credits') money = bnw.textFromElement(xFunds) if money == "DONTEXIST": print("The current money xpath is incorrect") exit(1) else: playerStatus['credits'] = int(money.replace(',','')) if debug: print('Querying current score') score = bnw.textFromElement(xScore) if score == "DONTEXIST": print("The current score xpath is incorrect") exit(1) else: playerStatus['score'] = int(score.replace(',','')) if debug: print('Querying sector type') sectorType = bnw.textFromElement(xSectorType) if sectorType == "DONTEXIST": print("The current sector type xpath doesn't exist") exit(1) else: playerStatus['sectorType'] = sectorType if debug: print('Querying sector port') # Sector Port needs special handling sectorPort = bnw.textFromElement(xSectorPort) if sectorPort == "DONTEXIST": print('xSectorPort did not exist') exit(1) else: fixedPort = sectorPort.replace('Trading port: ','') playerStatus['sectorPort'] = fixedPort # Cargoes if debug: print('Querying Ore Cargo') oreCargo = bnw.textFromElement(xOreCargo) if score == "DONTEXIST": print("The current Ore xpath is incorrect") exit(1) else: playerStatus['ore'] = int(oreCargo.replace(',','')) if debug: print('Querying Organics Cargo') organicCargo = bnw.textFromElement(xOrganicCargo) if score == "DONTEXIST": print("The current Organics xpath is incorrect") exit(1) else: playerStatus['organics'] = int(organicCargo.replace(',','')) if debug: print('Querying Goods Cargo') goodsCargo = bnw.textFromElement(xGoodsCargo) if score == "DONTEXIST": print("The current Goods xpath is incorrect") exit(1) else: playerStatus['goods'] = int(goodsCargo.replace(',','')) if debug: print('Querying Energy Cargo') energy = bnw.textFromElement(xEnergy) if score == "DONTEXIST": print("The current Energy xpath is incorrect") exit(1) else: playerStatus['energy'] = int(energy.replace(',','')) if debug: print('Querying colonists') colonists = bnw.textFromElement(xColonists) if score == "DONTEXIST": print("The current Colonists xpath is incorrect") exit(1) else: playerStatus['colonists'] = int(colonists.replace(',','')) # Determine the available warps warpNumber = 1 warps = [] while True: currentWarp = bnw.textFromElement("html/body/table[2]/tbody/tr/td[3]/table[6]/tbody/tr[1]/td/div/table/tbody/tr[{}]/td[1]/a".format(warpNumber)) if debug: print('Querying Current Warp') if currentWarp == "DONTEXIST": break else: # => 0 warps.append(currentWarp.replace('=> ','')) warpNumber += 1 playerStatus['warps'] = warps return playerStatus
def getShipStatus(): debug = False shipStatus = {} xBanner = "html/body/h1" xCredits = "html/body/div[1]/table[1]/tbody/tr/td[3]/strong" xHolds = "html/body/div[1]/table[2]/tbody/tr/td[2]/table/tbody/tr[1]/td[2]/strong" xEnergy = "html/body/div[1]/table[2]/tbody/tr/td[3]/table/tbody/tr[1]/td[2]/strong" xAverageTechLevel = "html/body/div[1]/table[2]/tbody/tr/td[1]/table/tbody/tr[12]/td[2]" xHull = "html/body/div[1]/table[2]/tbody/tr/td[1]/table/tbody/tr[2]/td[2]" xEngines = "html/body/div[1]/table[2]/tbody/tr/td[1]/table/tbody/tr[3]/td[2]" xPower = "html/body/div[1]/table[2]/tbody/tr/td[1]/table/tbody/tr[3]/td[2]" xComputer = "html/body/div[1]/table[2]/tbody/tr/td[1]/table/tbody/tr[5]/td[2]" xSensors = "html/body/div[1]/table[2]/tbody/tr/td[1]/table/tbody/tr[6]/td[2]" xArmor = "html/body/div[1]/table[2]/tbody/tr/td[1]/table/tbody/tr[7]/td[2]" xShields = "html/body/div[1]/table[2]/tbody/tr/td[1]/table/tbody/tr[8]/td[2]" xBeamWeapons = "html/body/div[1]/table[2]/tbody/tr/td[1]/table/tbody/tr[9]/td[2]" xTorpedoLaunchers = "html/body/div[1]/table[2]/tbody/tr/td[1]/table/tbody/tr[10]/td[2]" xCloak = "html/body/div[1]/table[2]/tbody/tr/td[1]/table/tbody/tr[11]/td[2]" xOre = "html/body/div[1]/table[2]/tbody/tr/td[2]/table/tbody/tr[2]/td[2]" xOrganics = "html/body/div[1]/table[2]/tbody/tr/td[2]/table/tbody/tr[3]/td[2]" xGoods = "html/body/div[1]/table[2]/tbody/tr/td[2]/table/tbody/tr[4]/td[2]" xColonists = "html/body/div[1]/table[2]/tbody/tr/td[2]/table/tbody/tr[5]/td[2]" xSpaceBeacons = "html/body/div[1]/table[2]/tbody/tr/td[3]/table/tbody/tr[4]/td[2]" xWarpEditors = "html/body/div[1]/table[2]/tbody/tr/td[3]/table/tbody/tr[5]/td[2]" xGenesisTorpedoes = "html/body/div[1]/table[2]/tbody/tr/td[3]/table/tbody/tr[6]/td[2]" xMineDeflectors = "html/body/div[1]/table[2]/tbody/tr/td[3]/table/tbody/tr[7]/td[2]" xEmergencyWarpDev = "html/body/div[1]/table[2]/tbody/tr/td[3]/table/tbody/tr[8]/td[2]" xArmorPoints = "html/body/div[1]/table[2]/tbody/tr/td[2]/table/tbody/tr[8]/td[2]" xFighters = "html/body/div[1]/table[2]/tbody/tr/td[2]/table/tbody/tr[9]/td[2]" xTorpedoes = "html/body/div[1]/table[2]/tbody/tr/td[2]/table/tbody/tr[10]/td[2]" xEscapePod = "html/body/div[1]/table[2]/tbody/tr/td[3]/table/tbody/tr[9]/td[2]" xFuelScoop = "html/body/div[1]/table[2]/tbody/tr/td[3]/table/tbody/tr[10]/td[2]" xLastSeenShipDev = "html/body/div[1]/table[2]/tbody/tr/td[3]/table/tbody/tr[11]/td[2]" simples = [ ["Average tech level", xAverageTechLevel], ["Hull", xHull], ["Engines", xEngines], ["Power", xPower], ["Computer", xComputer], ["Sensors", xSensors], ["Armor", xArmor], ["Shields", xShields], ["Beam Weapons", xBeamWeapons], ["Torpedo launchers", xTorpedoLaunchers], ["Cloak", xCloak], ["Ore", xOre], ["Organics", xOrganics], ["Goods", xGoods], ["Colonists", xColonists], ["Space Beacons", xSpaceBeacons], ["Warp Editors", xWarpEditors], ["Genesis Torpedoes", xGenesisTorpedoes], ["Mine Deflectors", xMineDeflectors], ["Emergency Warp Device", xEmergencyWarpDev] ] if debug: print("Attempting to extract the ship tech levels and other status") # retrieve the current page currentPage = bnw.getPage() baseURL = ('/').join(currentPage.split('/')[:-1]) shipStatusPage = "{}/report.php".format(baseURL) mainPage = "{}/main.php".format(baseURL) bnw.loadPage(shipStatusPage) time.sleep(2) bannerText = bnw.textFromElement(xBanner) if bannerText == "DONTEXIST": print("Unable to load player ship status page") exit(1) if bannerText != "Ship Report": print("Unexpected Banner Text: {}".format(bannerText)) exit(1) for currentSimple in simples: itemName = currentSimple[0] itemXpath = currentSimple[1] rawValue = bnw.textFromElement(itemXpath) if debug: print("itemName: {}, rawValue: {}".format(itemName, rawValue)) if rawValue == "DONTEXIST": print("xpath is incorrect for {}".format(itemName)) exit(1) value = toNumber(rawValue.replace('Level ','').replace(',','')) shipStatus[itemName] = value # current / max handling shipStatus["Holds"], shipStatus["HoldsMax"] = currentMax(xHolds) shipStatus["Energy"], shipStatus["EnergyMax"] = currentMax(xEnergy) shipStatus["ArmorPts"], shipStatus["ArmorMax"] = currentMax(xArmorPoints) shipStatus["Fighters"], shipStatus["FightersMax"] = currentMax(xFighters) shipStatus["Torpedoes"],shipStatus["TorpedoesMax"] = currentMax(xTorpedoes) # Yes / No handling shipStatus["EscapePod"] = yesOrNo(xEscapePod) shipStatus["FuelScoop"] = yesOrNo(xFuelScoop) shipStatus["LastShipSeenDev"] = yesOrNo(xLastSeenShipDev) # finally, grab the credits also rawValue = bnw.textFromElement(xCredits) if rawValue == "DONTEXIST": print("xpath is incorrect for credits") exit(1) value = toNumber(rawValue.replace(',', '').replace('Credits:','')) shipStatus["Credits"] = value # return to the main page bnw.loadPage(mainPage) return shipStatus
def yesOrNo(xpath): rawValue = bnw.textFromElement(xpath) if rawValue == "Yes": return True else: return False
def lrScan(sector): # retrieve the current page currentPage = bnw.getPage() baseURL = ('/').join(currentPage.split('/')[:-1]) scanURL = "{}/lrscan.php?sector={}".format(baseURL, sector) # load the page scanResult = {} bnw.loadPage(scanURL) verifyText = bnw.textFromElement(xBanner) if not "Sector {}".format(sector) in verifyText: print("Illegal sector specified: {}".format(sector)) exit(1) # Retrieve any links out of the sector linksText = bnw.textFromElement(xLinks) if linksText == "DONTEXIST": print("xLinks is incorrect - aborting") exit(1) scanResult['links'] = linksText.replace(' ', '').split(',') # Retrieve any ships in the sector shipsText = bnw.textFromElement(xShips) if shipsText == "DONTEXIST": print("xShips is incorrect - aborting") exit(1) scanResult['ships'] = shipsText.replace(' ', '').split(',') # Retrieve port info - if any portText = bnw.textFromElement(xPort) if portText == "DONTEXIST": print("xPort is incorrect - aborting") exit(1) else: scanResult['port'] = portText # Retrieve any planets in the sector planetsText = bnw.textFromElement(xPlanets) if planetsText == "DONTEXIST": print("xPlanets is incorrect - aborting") exit(1) else: scanResult['planets'] = planetsText.replace(' ', '').split(',') # Retrieve any mines in the sector minesText = bnw.textFromElement(xMines) if minesText == "DONTEXIST": print("xMines is incorrect - aborting") exit(1) print('minesText: "{}"'.format(minesText)) scanResult['mines'] = int(minesText.replace(', ', '')) # Retrieve any fighters in the sector fightersText = bnw.textFromElement(xFighters) if fightersText == "DONTEXIST": print("xFighters is incorrect - aborting") exit(1) scanResult['fighters'] = int(fightersText.replace(',', '')) # Important - Return to the original page! bnw.loadPage(currentPage) return scanResult