示例#1
0
def do_work(worker, moves_gen):
    seen_gyms = set()

    for position in moves_gen:
        try:
            map_objects = worker.do_get_map_objects(position)
        except GaveUp:
            log.warning("Gave up getting map objects at " + str(position))
            continue

        gyms = []
        try:
            if map_objects is None:  # can this ever happen ??
                log.warning(
                    "Did not get any map objects at {}, moving on".format(
                        str(map_objects)))
            else:
                gyms = parse_gyms(map_objects)
        except StopIteration:
            log.warning("Iteration over forts failed " +
                        str(map_objects))  # can this ever happen ?
            pass
        for gym in gyms:
            beh_process_single_gmo_gym_no_dups(worker, seen_gyms, gym,
                                               position)
示例#2
0
def beh_do_scanner_bot(pogoservice, moves_generator, delay):
    last_scanned_position = None
    for move in moves_generator:
        current_position = move['coordinates']
        gym_id = move['gym_id']
        try:
            map_objects = pogoservice.do_get_map_objects(current_position)
            gyms = parse_gyms(map_objects)
        except GaveUpApiAction:  # this should not really happen
            log.error("Giving up on location {} for gym {}".format(str(current_position), gym_id))
            continue
        if gyms is not None:
            try:
                gmo_gym = next(x for x in gyms if x["id"] == gym_id)
                do_with_backoff_for_deadlock(lambda: create_or_update_gym_from_gmo2(gym_id, gmo_gym))
                if gmo_gym is None:
                    log.error("get_map_objects did not give us gym")
            except StopIteration:
                print("gym " + gym_id + "was not found at location " + str(last_scanned_position))

        last_scanned_position = current_position

        time.sleep(2 + random.random())
        try:
            b = pogoservice.do_gym_get_info(current_position, current_position, gym_id)
            __log_info(pogoservice, "Sending gym {} to db".format(gym_id))
            update_gym_from_details(b)
        except GaveUpApiAction:
            time.sleep(20)
            __log_error(pogoservice, "Gave up on gym " + gym_id + " " + str(current_position))
            pass
        time.sleep(delay)
示例#3
0
def beh_gym_scan(pogoservice, moves_generator, delay):
    seen_gyms = set()
    last_scanned_position = None
    for move in moves_generator:
        current_position = move['coordinates']
        gym_id = move['gym_id']
        try:
            gyms = parse_gyms(pogoservice.do_get_map_objects(current_position))
        except GaveUpApiAction:  # this should not really happen
            log.error("Giving up on location {} for gym {}".format(str(current_position), gym_id))
            continue
        if gyms is not None:
            try:
                gmo_gym = next(x for x in gyms if x["id"] == gym_id)
                beh_process_single_gmo_gym_no_dups(pogoservice, seen_gyms, gmo_gym, current_position)
            except StopIteration:
                print("gym " + gym_id + "was not found at location " + str(last_scanned_position))

        last_scanned_position = current_position
        time.sleep(delay)