def do_it(session, islandList, time): """ Parameters ---------- session : ikabot.web.session.Session """ # this dict will contain all the cities from each island # as they where in last scan cities_before_per_island = {} while True: # this is done inside the loop because the user may colonize in a new island if islandList != []: islandsIds = islandList else: islandsIds = getIslandsIds(session) for islandId in islandsIds: html = session.get(island_url + islandId) island = getIsland(html) # cities in the current island cities_now = [ city_space for city_space in island['cities'] if city_space['type'] != 'empty' ] #loads the islands non empty cities into ciudades # if we haven't scaned this island before, # save it and do nothing if islandId not in cities_before_per_island: cities_before_per_island[islandId] = cities_now.copy() else: cities_before = cities_before_per_island[islandId] # someone disappeared for city_before in cities_before: if city_before['id'] not in [ city_now['id'] for city_now in cities_now ]: # we didn't find the city_before in the cities_now msg = _( 'the city {} of the player {} disappeared in {} {}:{} {}' ).format(city_before['name'], city_before['Name'], materials_names[int(island['good'])], island['x'], island['y'], island['name']) sendToBot(session, msg) # someone colonised for city_now in cities_now: if city_now['id'] not in [ city_before['id'] for city_before in cities_before ]: # we didn't find the city_now in the cities_before msg = _('{} founded {} in {} {}:{} {}').format( city_now['Name'], city_now['name'], materials_names[int(island['good'])], island['x'], island['y'], island['name']) sendToBot(session, msg) wait(time * 60)
def do_it(session, islandList, time, fights): """ Parameters ---------- session : ikabot.web.session.Session Session object islandList : list[dict] A list containing island objects which should be searched, if an empty list is passed, all the user's colonised islands are searched time : int The time in minutes between two consecutive seraches fights : str String that can either be y or n. Indicates whether or not to scan for fight activity on islands """ # this dict will contain all the cities from each island # as they where in last scan cities_before_per_island = {} while True: # this is done inside the loop because the user may colonize in a new island if islandList != []: islandsIds = islandList else: islandsIds = getIslandsIds(session) for islandId in islandsIds: html = session.get(island_url + islandId) island = getIsland(html) # cities in the current island cities_now = [ city_space for city_space in island['cities'] if city_space['type'] != 'empty' ] # loads the islands non empty cities into ciudades # if we haven't scaned this island before, # save it and do nothing if islandId not in cities_before_per_island: cities_before_per_island[islandId] = cities_now.copy() else: cities_before = cities_before_per_island[islandId] # someone disappeared for city_before in cities_before: if city_before['id'] not in [ city_now['id'] for city_now in cities_now ]: # we didn't find the city_before in the cities_now msg = _( 'The city {} of the player {} disappeared in {} {}:{} {}' ).format(city_before['name'], city_before['Name'], materials_names[int(island['tradegood'])], island['x'], island['y'], island['name']) sendToBot(session, msg) if fights.lower() == 'y': for city_now in cities_now: if city_now['id'] == city_before['id']: if 'infos' in city_now and 'infos' not in city_before and 'armyAction' in city_now[ 'infos'] and city_now['infos'][ 'armyAction'] == 'fight': msg = _( 'A fight started in the city {} of the player {} on island {} {}:{} {}' ).format( city_before['name'], city_before['Name'], materials_names[int( island['tradegood'])], island['x'], island['y'], island['name']) sendToBot(session, msg) if 'infos' not in city_now and 'infos' in city_before and 'armyAction' in city_before[ 'infos'] and city_before['infos'][ 'armyAction'] == 'fight': msg = _( 'A fight stopped in the city {} of the player {} on island {} {}:{} {}' ).format( city_before['name'], city_before['Name'], materials_names[int( island['tradegood'])], island['x'], island['y'], island['name']) sendToBot(session, msg) # someone colonised for city_now in cities_now: if city_now['id'] not in [ city_before['id'] for city_before in cities_before ]: # we didn't find the city_now in the cities_before msg = _( 'Player {} created a new city {} in {} {}:{} {}' ).format(city_now['Name'], city_now['name'], materials_names[int(island['tradegood'])], island['x'], island['y'], island['name']) sendToBot(session, msg) cities_before_per_island[islandId] = cities_now.copy( ) # update cities_before_per_island for the current island wait(time * 60)