def celebrate(self): config = util.readConfig() villagesId = config["VILLAGESID"] while True: if (self.isCelebrate()): for villageId in villagesId: self.browser.get(config["SERVER"] + "/build.php" + "?newdid=" + str(villageId) + "&id=21&type=2") util.waitUntil(self.browser, 5, 'build_logo') time.sleep(1) try: celebrateStatusContainer = self.browser.find_element_by_xpath( "//div[@class='villageListBarBox']/div[@class='bar']" ) celebrateStatus = str( celebrateStatusContainer.get_attribute( 'style')).split(':')[1] print("<< Celebrate >> Progress: " + str(celebrateStatus)) time.sleep(1) except: print("Error") else: break
def sendResourceToVillageId(self, villageId): config = util.readConfig() capitalId = config["VILLAGESID"][0] util.goToVillageBuiding(self.browser, capitalId, '36') util.waitUntil(self.browser, 5, 'build_logo') self.inputResource() self.inputCoordinate(villageId) self.submitResource(capitalId, villageId)
def build(self): time.sleep(1) config = util.readConfig() cities = util.readCity() buildingList = util.readBuilding() villages = config["VILLAGESID"] for villageId in villages: if (self.isBroken(villageId)): for city in cities["cities"]: positionId = city["id"] buildName = city["building"] buildingId = util.getKeyByValue(buildingList, buildName) self.createUnit(villageId, buildingId, positionId) self.upgradeToMaxLevel(villageId, positionId)
def create(self): config = util.readConfig() villagesId = config["VILLAGESID"] villageId = self.getVillageIdWithSettler() if villageId is None: villageId = self.createSettler() newVillageId = self.findNewVillage(villageId) villagesId.append(newVillageId) config["VILLAGESID"] = villagesId util.writeConfig(config) print("<< Create Village >> New village id: " + str(newVillageId)) self.sendResourceToVillageId(newVillageId) time.sleep(1)
def login(isHeadless): config = readConfig() print('## Connect to ' + config['SERVER'] + ' ##') options = Options() options.headless = isHeadless options.add_argument('disable-dev-shm-usage') browser = webdriver.Chrome(executable_path='Lib/chromedriver', chrome_options=options) browser.get(config['SERVER']) usernameInput = browser.find_element_by_name('user') passwordInput = browser.find_element_by_name('pw') usernameInput.send_keys(config['USERNAME']) passwordInput.send_keys(config['PASSWORD']) submitButton = browser.find_element_by_name('s2') print('## Login... ##') submitButton.click() waitUntil(browser, 5, 'villageBuildings') print(' ## Login Successfully ##') return browser
def goToFoundNewVillage(self, villageId, newVillageId): config = util.readConfig() self.browser.get(config["SERVER"] + "/a2b.php?newdid=" + str(villageId) + "&id=" + str(newVillageId) + "&s=1") util.waitUntil(self.browser, 5, 'troopstipo')
def goToDorf1(self, villageId): config = util.readConfig() self.browser.get(config["SERVER"] + '/dorf1.php?newdid=' + str(villageId)) util.waitUntil(self.browser, 5, 'contentContainer')
import Service.util as util import time config = util.readConfig() def isMaxLevel(browser): try: browser.find_element_by_class_name('clocks').text return True except: return False def getBuildCoolDown(browser): coolDownTime = browser.find_element_by_class_name('clocks').text coolDownTimeInMinute = str(coolDownTime).split(":")[1] coolDownTimeInSecond = str(coolDownTime).split(":")[2] buildingName = browser.find_element_by_class_name('titleInHeader').text print("###### " + buildingName + " time: " + coolDownTimeInMinute + " minute " + coolDownTimeInSecond + " second ######") return (int(coolDownTimeInMinute) * 60) + int(coolDownTimeInSecond) + 0.5 def buildUnit(browser): if (isMaxLevel(browser)): coolDownTimeInSecond = getBuildCoolDown(browser) util.getUpgradeButton(browser).click() time.sleep(coolDownTimeInSecond) else: raise Exception('Your building reach to max level.')
def receive(self): config = readConfig() print('## Receiving ... ##') self.browser.get(config['SERVER'] + '/hero_inventory.php?revive=1') time.sleep(1)