예제 #1
0
 def new_place(self, place, lat, lon):
     post = Place(city_id=self._id,
                  place=place,
                  lat=lat,
                  lon=lon,
                  cordinates=[(lat, lon)],
                  city=self.city)
     post.save_to_mongo()
예제 #2
0
    def insert_new_place(self, place: Place):
        place_args = self.__exec_procedure('put_new_place', 0, place.name,
                                           place.logo_path, place.image_path,
                                           place.description,
                                           place.question_title, place.address)

        if place_args[0] != 0:
            return 1

        # selecting inserted place id from out args
        place.id = place_args[1]

        # inserting answers
        if place.answers is not None:
            for answer in place.answers:
                result = self.insert_new_answer(place.id, answer.title,
                                                answer.is_right,
                                                answer.description)
                if result[0] != 0:
                    return 2
                else:
                    answer.id = result[1]

        # inserting routes
        if place.routes is not None:
            for route in place.routes:
                result = self.__exec_procedure('put_place_route', place.id,
                                               route.id)
                if result[0] != 0:
                    return 3

        return place
예제 #3
0
def put_new_place():
    content = request.json
    place = Place(p_id=content['id'],
                  name=content['name'],
                  logo_path=content['logo_path'],
                  image_path=content['image_path'],
                  description=content['description'],
                  question_title=content['question_title'],
                  address=content['address'],
                  answers=list(
                      map(
                          lambda ans: Answer(ans['id'], ans['title'], ans[
                              'is_right'], ans['description']),
                          content['answers'])),
                  routes=list(
                      map(
                          lambda route: RouteInfo(route['id'], route['name'],
                                                  route['logo_path']),
                          content['routes'])))

    result = db.insert_new_place(place)

    if result == 1:
        return abort(400, 'Invalid place data')
    elif result == 2:
        return abort(400, 'Invalid answers data. Place was added.')
    elif result == 3:
        return abort(400, 'Invalid routes data. Place was added')
    else:
        return to_json(result)
예제 #4
0
    def fetch_full_places(self) -> List[Place]:
        places_result = self.__fetch_from_procedure('get_full_places')
        places = list(map(lambda db_tuple: Place(*db_tuple), places_result))

        for place in places:
            place.answers = self.fetch_answers_by_place(place.id)
            place.routes = self.fetch_routes_by_place(place.id)

        return places
예제 #5
0
def addPlacePagePost():
    place = Place(request.form["name"])
    db.session.add(place)
    db.session.commit()
    places = Place.query.all()
    return render_template("place.html",
                           type="add",
                           places=places,
                           result="Ok")
예제 #6
0
    def fetch_place(self, place_id) -> Place:
        place_raw = self.__fetch_from_procedure('get_place', place_id)

        if len(place_raw) == 0:
            return None

        place = Place(*place_raw[0])

        # fetching routes
        routes_raw = self.__fetch_from_procedure('get_routes_by_place',
                                                 place.id)
        place.routes = list(map(lambda route: RouteInfo(*route), routes_raw))

        # fetching answers
        answers_raw = self.__fetch_from_procedure('get_answers_by_place',
                                                  place.id)
        place.answers = list(map(lambda answer: Answer(*answer), answers_raw))

        return place
예제 #7
0
def post():
    """function or route that create a new place"""
    idplace = storage.get("City", city_id)
    if idplace is None:
        abort(404)
    if not request.get_json():
        return make_response(jsonify({'error': 'Not a JSON'}), 400)
    info = request.get_json()
    if 'Place_id' not in info
        return make_response(jsonify({'error': 'Missing Place'}), 400)
    infoPlace = storage.get("Place", info['Place_id'])
    if infoPlace is None:
        abort(404)
    if 'name' not in info:
        return make_response(jsonify({'error': 'Missing name'}), 400)
    info['city_id'] = city_id
    newPlace = Place(**info)
    newPlace.save()
    return make_response(jsonify(newPlace.to_dict()), 201)
예제 #8
0
    def fight(self, opponent_nick_name):
        """
        Allows a player to fight

        Args:
            opponent_nick_name (str): Nick name of the opponent character
        """
        state = get_state()
        character = state['character']

        if not character:
            print "You have not assumed a character yet!"
            print "Run - "
            print "python zestwar.py -- --help"
            return

        character_name = get_character_name(character)
        place = state['place']

        if not place:
            print "You have to explore a place to start fighting!"
            print "Run - "
            print "python zestwar.py -- --help"
            return

        place_name = get_place_name(place)

        if opponent_nick_name == character:
            print "You cannot fight against yourself!"
            return

        if not character_exists_at_place(place, opponent_nick_name):
            print "The character '{0}' does not exist at '{1}' to fight".format(
                opponent_nick_name, place_name)
            print "Explore {0} again!".format(place)
            return

        # instantiate place
        place = Place(place, place_name, get_characters)
        # instantiate character
        character = Character(character, character_name,
                              get_weightage(character))
        player = Player(character, place)

        opponent_name = get_character_name(opponent_nick_name)
        opponent_character = Character(opponent_nick_name, opponent_name,
                                       get_weightage(opponent_nick_name))

        opponent = Player(opponent_character, place)
        experience = player.fight(opponent)
        save_experience(experience)
        print "Congrats! You gained {0} experience points.".format(experience)
        print "Your total experience is now at {0} points".format(
            get_total_experience())
예제 #9
0
def update_place(place_id):
    content = request.json

    result = db.update_place(
        Place(place_id, content['name'], content['logo_path'],
              content['image_path'], content['description'],
              content['question_title'], content['address'],
              list(map(lambda route: RouteInfo(**route), content['routes'])),
              list(map(lambda answer: Answer(**answer), content['answers']))))

    if result is None:
        return abort(400, 'Invalid request')
    else:
        return to_json(result)
예제 #10
0
    def get_venues_near(self, point: Point, radius: int, n=5):
        poi_type = ['arts', 'outdoors', 'sights']
        limit = 50  # Foursquare limit
        if limit > n: limit = n
        params = {
            'intent': 'browse',
            'll': str(point.latitude) + ',' + str(point.longitude),
            'radius': radius,
            'section': poi_type[0],
            'limit': limit,
            'offset': 0
        }

        places = []
        for params['section'] in poi_type:
            try:
                res = self.client.venues.explore(params)
                num_res = res['totalResults']
                if num_res > n: num_res = n
                places.extend(res['groups'][0]['items'])

                for params['offset'] in range(limit, num_res, limit):
                    places.extend(
                        self.client.venues.explore(params)['groups'][0]
                        ['items'])
            except foursquare.FoursquareException as e:
                pass
        res = []
        for place in places[:2]:
            p = Place(Point(0, 0), [])
            tips = self.get_tips_for_vid(place['venue']['id'])[:5]
            photos = self.get_photos_for_vid(place['venue']['id'])[:15]
            p.set_place_info(place['venue']['name'], place['venue']['rating'],
                             tips, photos)
            res.append(p)
        return res
예제 #11
0
def put_new_place():
    session = get_session()
    content = g.data

    locale = get_post_locale(session)

    if session.query(City).get(content['city_id']) is None:
        session.close()
        abort(400, "City with id = %s not found" % content['city_id'])
        return

    geolocation = Geolocation(
        latitude=content['latitude'],
        longitude=content['longitude']
    )

    categories = []

    for category_id in content['categories']:
        category = session.query(Category).get(category_id)

        if category is None:
            session.close()
            abort(400, "Category with id = %s not found" % category_id)
            return

        categories.append(category)

    place = Place(
        image_link=content['image_link'],
        city_id=content['city_id'],
        geolocation=geolocation,
        categories=categories
    )

    name_id = str(uuid4())
    locale_string = LocaleString(
        id=name_id,
        locale=locale,
        text=content['name']
    )
    place.name_id = name_id
    place.name.set(locale_string)

    description_id = str(uuid4())
    locale_string = LocaleString(
        id=description_id,
        locale=locale,
        text=content['description']
    )
    place.description_id = description_id
    place.description.set(locale_string)

    address_id = str(uuid4())
    locale_string = LocaleString(
        id=address_id,
        locale=locale,
        text=content['address']
    )
    place.address_id = address_id
    place.address.set(locale_string)

    if 'audioguide_link' in content:
        audioguide_link_id = str(uuid4())
        locale_link = LocaleLink(
            id=audioguide_link_id,
            locale=locale,
            path=content['audioguide_link']
        )
        place.audioguide_link_id = audioguide_link_id
        place.audioguide_link.set(locale_link)

    session.add(place)

    session.commit()
    session.close()

    return 'ok'
예제 #12
0
 def get_places1(self):
     return Place.from_all_topic(self.city)
예제 #13
0
 def get_places(self):
     return Place.from_city(self._id)