예제 #1
0
파일: research.py 프로젝트: NickPPC/Olivia
def researchTech(planetName, techName):
    menu.navigate_to_planet(planetName)
    go_to_research()

    if techName not in researchTranslation:
        return Event(Event.ERROR, 0, planetName, 'Technology is not valid')

    try:

        clickTechElement(planetName, techName)
        time.sleep(3)
        cost = _get_current_tech_cost()

        driver().find_element_by_class_name('build-it').click()
        # TODO: improve by using construction time extracted when building
        log.info(
            '{} research started for {} metal, {} cristal and {} deuterium'.
            format(techName, cost[METAL], cost[CRISTAL], cost[DEUTERIUM]))
        return Event(Event.RESEARCH_IN_PROGRESS,
                     getNextTimeAvailability() - time.time(), planetName,
                     techName)

    except Exception as e:
        log.error('Impossible to do this research {} on {}\n {} : {}'.format(
            techName, planetName,
            type(e).__name__, str(e)))
        menu.navigate_to_overview()
        return Event(
            Event.ERROR, 0, planetName,
            'Impossible to research this technology, {}'.format(str(e)))
예제 #2
0
파일: research.py 프로젝트: NickPPC/Olivia
def getNextTimeAvailability():
    menu.navigate_to_overview()
    try:
        timeLeft = driver().find_element_by_id(
            'researchCountdown').get_attribute('innerHTML')
        return time.time() + formatted_time_to_seconds(timeLeft)
    except Exception as e:
        log.warn('Exception {} : {}'.format(type(e).__name__, str(e)))
        return 0
예제 #3
0
def getNextTimeAvailability(planetName):
    menu.navigate_to_planet(planetName)
    menu.navigate_to_overview()

    try:
        timeLeft = driver().find_element_by_id('Countdown').get_attribute('innerHTML')
        return time.time() + formatted_time_to_seconds(timeLeft)
    except Exception as e:
        log.warn('Exception {} : {}. Discard if no construction in progress'.format(type(e).__name__, str(e)))
        return 0
예제 #4
0
파일: research.py 프로젝트: NickPPC/Olivia
def get_in_progress_research():
    menu.navigate_to_overview()

    try:
        research_overview = driver().find_elements_by_class_name(
            'content-box-s')[1]
        in_progres = research_overview.find_element_by_class_name('first')
        cancel_link = in_progres.find_elements_by_tag_name('a')[0]
        cancel_action = cancel_link.get_attribute('onClick')
        log.debug(cancel_action)
        # 3 numbers after 'cancelResearch(' (15 letters)
        item_id = cancel_action[15:18]

        for research, details in researchTranslation.items():
            if item_id in details:
                return research

        log.error('research not identified: {}'.format(item_id))
        return None
    except Exception as e:
        log.warn('Exception {} : {}. Discard if no researh in progress'.format(
            type(e).__name__, str(e)))
        return None
예제 #5
0
def get_in_progress_building(planet_name):
    menu.navigate_to_planet(planet_name)
    menu.navigate_to_overview()

    try:
        building_overview = driver().find_elements_by_class_name('content-box-s')[0]
        in_progres = building_overview.find_element_by_class_name('first')
        cancel_link = in_progres.find_elements_by_tag_name('a')[0]
        cancel_action = cancel_link.get_attribute('onClick')
        log.debug(cancel_action)
        # 3 numbers after 'cancelProduction(' (17 letters)
        item_id = cancel_action[17:19].strip(',')

        x = - len(item_id)
        for building in buildingTranslation:
            (_, _, name) = buildingTranslation[building]
            if item_id in name[x:]:
                return building

        log.error('building not identified: {}'.format(item_id))
        return None
    except Exception as e:
        log.warn('Exception {} : {}. Discard if no construction in progress'.format(type(e).__name__, str(e)))
        return None
예제 #6
0
def upgrade_building(planetName, buildingName):

    if buildingName not in buildingTranslation:
        return Event(Event.ERROR, 0, planetName, 'Building is not valid')

    menu.navigate_to_planet(planetName)
    go_to(buildingName)

    try:

        _clickBuildingElement(buildingName)
        time.sleep(3)
        cost = _get_current_building_cost()

        driver().find_element_by_class_name('build-it').click()
        #TODO: improve by using construction time extracted when building

        log.info('{} construction started for {} metal, {} cristal and {} deuterium'.format(buildingName,
                                                                        cost[METAL], cost[CRISTAL], cost[DEUTERIUM]))
        return Event(Event.BUILDING_IN_PROGRESS, getNextTimeAvailability(planetName) - time.time(), planetName, buildingName)
    except Exception as e:
        log.error('Impossible to upgrade this building {} on {}\n {} : {}'.format(buildingName, planetName, type(e).__name__, str(e)))
        menu.navigate_to_overview()
        return Event(Event.ERROR, 0, planetName, 'Impossible to upgrade this building, {}'.format(str(e)))