Exemple #1
0
def add(uid, name, logo=None):
    "TODO: normalize uid to lower case"
    if get_by_id(uid) != None:
        raise RestaurantExistError("uid = %s" % uid)
    restaurant = Restaurant(id=uid, uid=uid, name=name, logo=logo)
    restaurant.put()
    return restaurant
def getJsonFromFile(name):
    restaurant = Restaurant(name)
    restaurant.setReviews()
    restaurantList.append(restaurant)
    for restaurant in restaurantList:

        extractor = Extractor(restaurant.concentate())
        _summary = extractor.summary()
        for i, n in enumerate(
                sorted(_summary,
                       key=lambda k: len(_summary[k][0]) + len(_summary[k][1]),
                       reverse=True)):
            print(
                str(i + 1) + '.', '[' + n + ']',
                str(len(_summary[n][0])) + '/' + str(len(_summary[n][1])))

            print('\tpositive:')
            positive = _summary[n][0]
            if len(positive) > 3:
                positive = random.sample(positive, 3)
            for noun in positive:
                print('\t', norm(noun.sent))

            print('\tnegative:')
            negative = _summary[n][1]
            if len(negative) > 3:
                negative = random.sample(negative, 3)
            for noun in negative:
                print('\t', norm(noun.sent))
        break
Exemple #3
0
def add_restaurant():
    global restaurants
    if request.method == 'POST':
       print(request.get_json())
       newRest = request.get_json()
       restaurant = Restaurant(newRest['id'], newRest['name'], newRest['city'], newRest['parking'], newRest['rating'])
       menuList = newRest['menu']
       for menuItem in menuList:
          menuObject = Entree(menuItem['id'], menuItem['name'], menuItem['cuisine'], menuItem['dinner'])
          restaurant.addEntree(menuObject)
       restaurants.append(restaurant)
    return json.dumps({'success':True}), 200, {'ContentType':'application/json'}
Exemple #4
0
 def post(self):
     hashed_password = generate_password_hash(api.payload['password'], method='sha256')
     new_restaurant = Restaurant(email=api.payload['email'], ime_restorana=api.payload['ime_restorana'], jelo_1=api.payload['jelo_1'],jelo_2=api.payload['jelo_2'],jelo_3=api.payload['jelo_3'], password=hashed_password, admin=False)
     db.session.add(new_restaurant)
     db.session.commit()
     
     return {'message': 'New Restaurant created!'}, 201
 def get_by_id(self, rid):
     cursor = self.connection.execute(
         'SELECT * FROM restaurants WHERE rid = ?', (rid, ))
     if cursor.arraysize != 1:
         raise ValueError("Restaurant with Rid: " + rid + " does not exist")
     row = cursor.__next__()
     restaurant = Restaurant(row[0], row[1], row[2], row[3], row[4], row[5],
                             row[6], row[7])
     return restaurant
Exemple #6
0
def nextRecommendation(bot, chatid, messageid, index):
    recommendation = Recommendation(str(chatid))
    res = recommendation.getFacebookRestaurants()
    r = dumps(res[index], indent=4)
    restaurant = ""
    totExtraction = len(res)
    keyboard = []
    backInlineKeyboard = InlineKeyboardButton("< " + str(index),
                                              callback_data="4," +
                                              str(index - 1))
    centerInlineKeyboard = InlineKeyboardButton("• " + str(index + 1) + " •",
                                                callback_data="5," +
                                                str(index))
    nextInlineKeyboard = InlineKeyboardButton(str(index + 2) + " >",
                                              callback_data="4," +
                                              str(index + 1))
    nullInlineKeyboard = InlineKeyboardButton("   ", callback_data="5,0")
    if index - 1 >= 0:
        keyboard.append(backInlineKeyboard)
    else:
        keyboard.append(nullInlineKeyboard)

    keyboard.append(centerInlineKeyboard)
    if index + 1 < totExtraction:
        keyboard.append(nextInlineKeyboard)
    else:
        keyboard.append(nullInlineKeyboard)

    selectInlineKeyboard = InlineKeyboardButton("Scegli questo ristorante",
                                                callback_data="1," +
                                                str(index))
    annullaInlineKeyboard = InlineKeyboardButton("Annulla raccomandazione",
                                                 callback_data="2," +
                                                 str(index))
    fotoInlineKeyboard = InlineKeyboardButton("Mostra Foto",
                                              callback_data="3," + str(index))
    reply_markup = InlineKeyboardMarkup([
        keyboard, [selectInlineKeyboard], [fotoInlineKeyboard],
        [annullaInlineKeyboard]
    ])

    if index in range(0, totExtraction):
        restaurant = Restaurant(json.loads(r))
        #print(str(restaurant.about))
    bot.edit_message_text(chat_id=chatid,
                          message_id=messageid,
                          text=str(restaurant),
                          parse_mode=telegram.ParseMode.MARKDOWN,
                          disable_web_page_preview=True,
                          reply_markup=reply_markup)
Exemple #7
0
def sendRecommendation(bot, update, recommendation):
    #estraggo i ristoranti
    res = recommendation.getFacebookRestaurants()
    #calcolo quanti ne ho estratti
    totExtraction = len(res)
    if totExtraction > 0:
        bot.send_message(update.message.chat.id,
                         text="sono stati estratti " + str(totExtraction) +
                         " ristoranti da Facebook!")
        time.sleep(1)
        keyboard = []
        r = Restaurant(res[0])

        centerInlineKeyboard = InlineKeyboardButton("• 1 •",
                                                    callback_data="5,0")
        nextInlineKeyboard = InlineKeyboardButton("2 >", callback_data="4,1")
        nullInlineKeyboard = InlineKeyboardButton("   ", callback_data="5,0")

        keyboard.append(nullInlineKeyboard)
        keyboard.append(centerInlineKeyboard)
        if totExtraction > 1:
            keyboard.append(nextInlineKeyboard)
        else:
            keyboard.append(nullInlineKeyboard)

        selectInlineKeyboard = InlineKeyboardButton("Scegli questo ristorante",
                                                    callback_data="1,0")
        annullaInlineKeyboard = InlineKeyboardButton("Annulla raccomandazione",
                                                     callback_data="2,0")
        fotoInlineKeyboard = InlineKeyboardButton("Mostra Foto",
                                                  callback_data="3,0")
        reply_markup = InlineKeyboardMarkup([
            keyboard, [selectInlineKeyboard], [fotoInlineKeyboard],
            [annullaInlineKeyboard]
        ])
        bot.send_message(chat_id=update.message.chat.id,
                         text=str(r),
                         parse_mode=telegram.ParseMode.MARKDOWN,
                         disable_web_page_preview=True,
                         reply_markup=reply_markup)
    else:
        bot.send_message(
            update.message.chat.id,
            text=
            "Mi dispiace non ho trovato nessun ristorante nella tua zona...")
 def create_restaurant_from_lives_data(line, header_map):
     rid = 'laca_' + line[header_map['business_id']]
     name = line[header_map['name']].title()
     address = line[header_map['address']].title()
     city = line[header_map["city"]].title()
     state = line[header_map["state"]]
     zip_code = line[header_map["postal_code"]]
     latitude = line[header_map['latitude']]
     longitude = line[header_map['longitude']]
     restaurant = Restaurant(rid,
                             name,
                             address=address,
                             city=city,
                             state=state,
                             zip_code=zip_code,
                             latitude=latitude,
                             longitude=longitude)
     return restaurant
    def test_insert(self):
        conn = sqlite3.connect(':memory:')

        creator = RestaurantTableCreator(conn)
        creator.create_tables()
        storage = RestaurantStorage(conn)
        restaurant = Restaurant('test_123',
                                "Joe's Crabshack",
                                city="Los Angeles",
                                state='CA')
        storage.insert(restaurant)

        actual = storage.get_by_id(restaurant.rid)
        self.assertEqual(actual.rid, restaurant.rid)
        self.assertEqual(actual.name, restaurant.name)
        self.assertEqual(actual.address, restaurant.address)
        self.assertEqual(actual.city, restaurant.city)
        self.assertEqual(actual.state, restaurant.state)
        self.assertEqual(actual.zip_code, restaurant.zip_code)
        self.assertEqual(actual.latitude, restaurant.latitude)
        self.assertEqual(actual.longitude, restaurant.longitude)
Exemple #10
0
                option = session.query(Option).filter_by(des=opt_nm).first()

                if option is None:
                    last_option = session.query(Option).filter_by(
                        p_id=p_option.id).order_by(desc(Option.order)).first()
                    order = last_option.order if last_option else 0
                    option = Option({
                        'level': p_option.level + 1,
                        'order': order + 10,
                        'des': opt_nm,
                        'p_id': p_option.id
                    })
                    session.add(option)
                    session.flush()

        now_restaurant = Restaurant.get_by_place_id(session, r['id'])

        if now_restaurant is None:
            now_restaurant = Restaurant({
                'name':
                r['name'],
                'road_address':
                r['roadAddress'],
                'address':
                r['address'],
                'option_id':
                option.id,
                'phone':
                r['telDisplay'] if r['telDisplay'] else r['tel'],
                'lng':
                r['x'],
Exemple #11
0
def get_all():
    return Restaurant.query().fetch()
Exemple #12
0
def get_by_name(name):
    return Restaurant.query(Restaurant.name == name).fetch()
Exemple #13
0
entree1 = Entree(1, 'Chicken Marsala', 'Italian', True)
entree2 = Entree(2, 'Chicken Florentine', 'Italian', True);
entree3 = Entree(3, 'Fettucini Alfredo', 'Italian', True);
entree4 = Entree(4, 'Pepperoni Pizza', 'Italian', True);

entree5 = Entree(5, 'Chicken Tikka Masala', 'Indian', True);
entree6 = Entree(6, 'Chicken Kadahi', 'Indian', True);
entree7 = Entree(7, 'Tandoori Chicken', 'Indian', True);
entree8 = Entree(8, 'Butter Naan', 'Indian', True);
entree9 = Entree(9, 'Rogan Josh', 'Indian', True);

entree10 = Entree(10, 'Avocado Burger', 'American', True);
entree11 = Entree(11, 'Chicken Wings', 'American', True);
entree12 = Entree(12, 'Fillet Mignon', 'American', True);

restaurant1 = Restaurant('1', 'Ippolitos', 'Atlanta', True, 4)
restaurant1.addEntree(entree1)
restaurant1.addEntree(entree2)
restaurant1.addEntree(entree3)
restaurant1.addEntree(entree4)

restaurant2 = Restaurant('2', 'Maharaja', 'Dunwoody', True, 5)
restaurant2.addEntree(entree5)
restaurant2.addEntree(entree6)
restaurant2.addEntree(entree7)
restaurant2.addEntree(entree8)
restaurant2.addEntree(entree9)

restaurant3 = Restaurant('3', 'Friends', 'Suwanee', True, 5)
restaurant3.addEntree(entree10)
restaurant3.addEntree(entree11)
Exemple #14
0
def get_restaurants():

    entree1 = Entree(1, 'Chicken Marsala', 'Italian', True)
    entree2 = Entree(2, 'Chicken Florentine', 'Italian', True)
    entree3 = Entree(3, 'Fettucini Alfredo', 'Italian', True)
    entree4 = Entree(4, 'Pepperoni Pizza', 'Italian', True)

    entree5 = Entree(5, 'Chicken Tikka Masala', 'Indian', True)
    entree6 = Entree(6, 'Chicken Kadahi', 'Indian', True)
    entree7 = Entree(7, 'Tandoori Chicken', 'Indian', True)
    entree8 = Entree(8, 'Butter Naan', 'Indian', True)
    entree9 = Entree(9, 'Rogan Josh', 'Indian', True)

    entree10 = Entree(10, 'Avocado Burger', 'American', True)
    entree11 = Entree(11, 'Chicken Wings', 'American', True)
    entree12 = Entree(12, 'Fillet Mignon', 'American', True)

    restaurant1 = Restaurant('1', 'Ippolitos', 'Atlanta', True, 4)
    restaurant1.addEntree(entree1)
    restaurant1.addEntree(entree2)
    restaurant1.addEntree(entree3)
    restaurant1.addEntree(entree4)

    restaurant2 = Restaurant('2', 'Maharaja', 'Dunwoody', True, 5)
    restaurant2.addEntree(entree5)
    restaurant2.addEntree(entree6)
    restaurant2.addEntree(entree7)
    restaurant2.addEntree(entree8)
    restaurant2.addEntree(entree9)

    restaurant3 = Restaurant('3', 'Friends', 'Suwanee', True, 5)
    restaurant3.addEntree(entree10)
    restaurant3.addEntree(entree11)
    restaurant3.addEntree(entree12)

    restaurants = [restaurant1, restaurant2, restaurant3]
    schema = RestaurantSchema(many=True)
    restaurants = schema.dump(restaurants)
    return jsonify(restaurants)
    def fetch_restaurant(self):
        self.driver.get(self.url)
        _id = get_id_by_url(self.url)

        print('Fetching restaurant with id: ' + _id, flush=True)
        name = self.driver.find_element_by_class_name('heading_title').text

        try:
            total_rating = float(
                self.driver.find_element_by_class_name(
                    'ui_bubble_rating').get_attribute('content').replace(
                        ',', '.'))
        except:
            total_rating = -1

        try:
            ranking_position = int(
                self.driver.find_element_by_class_name('header_popularity').
                find_element_by_tag_name('b').find_element_by_tag_name(
                    'span').text.split('º ')[-1].split('#')[1].replace(
                        ',', ''))
        except:
            ranking_position = -1

        try:
            price = PRICE[get_language_by_url(self.driver.current_url)][
                self.driver.find_element_by_class_name(
                    'header_tags').text.replace(' ', '')]
        except:
            price = -1

        try:
            tags = self.driver.find_element_by_class_name(
                'header_links').text.split(', ')
        except:
            tags = ""

        try:
            street_address = self.driver.find_element_by_class_name(
                'street-address').text
        except:
            street_address = ""

        try:
            locality_address = self.driver.find_element_by_class_name(
                'locality').text
        except:
            locality_address = ""

        try:
            country_address = self.driver.find_element_by_class_name(
                'country-name').text
        except:
            country_address = ""

        try:
            phone = self.driver.find_element_by_class_name('phone').text
        except:
            phone = ""

        try:
            cuisines = self.driver.find_element_by_xpath(
                '//*[@id="taplc_restaurants_detail_info_content_0"]/div[2]/div/div[2]/div[2]'
            ).get_attribute('data-content').replace(', ', ',').split(',')
        except:
            cuisines = ""

        address = Address(street_address, locality_address, country_address)

        ratings = []
        for i in range(2, 6):
            try:
                rating_element = self.driver.find_element_by_xpath(
                    '//*[@id="taplc_restaurants_detail_info_content_0"]/div[3]/div['
                    + str(i) + ']')
            except:
                rating_element = None

            if rating_element:
                rating_name = rating_element.text
                try:
                    rating_value = RATING[
                        rating_element.find_element_by_class_name(
                            'ui_bubble_rating').get_attribute('class').split(
                                ' ')[-1]]
                except:
                    rating_value = -1
                rating = Rating(rating_name, rating_value)
                ratings.append(rating)

        restaurant = Restaurant(_id, name, total_rating, ranking_position,
                                price, tags, address, phone, cuisines, ratings)
        print('[COMPLETED]', flush=True)
        return restaurant.to_dict()
Exemple #16
0
def get_by_id(entity_id):
    return Restaurant.get_by_id(entity_id)
Exemple #17
0
def add_restaurant():
    geolocator = Nominatim()

    def allowed_file(filename):
        return '.' in filename and \
               filename.rsplit('.', 1)[1].lower() in app.config['ALLOWED_EXTENSIONS']

    name = request.args['name']
    addr1 = request.args['address1']
    addr2 = request.args['address2']
    menu = request.args['menu']
    if 'park' in request.args:
        park = request.args['park']
    else:
        park = None
    if 'offer' in request.args:
        offer = request.args['offer']
    else:
        offer = None
    if 'card' in request.args:
        card = request.args['card']
    else:
        card = None
    if 'wifi' in request.args:
        wifi = request.args['wifi']
    else:
        wifi = None
    if 'cost' in request.args:
        cost = request.args['cost']
    else:
        wifi = None
    if 'delivery' in request.args:
        delivery = request.args['delivery']
    else:
        delivery = None
    if 'reservation' in request.args:
        reservation = request.args['reservation']
    else:
        reservation = None
    if 'terrace' in request.args:
        terrace = request.args['terrace']
    else:
        terrace = None
    phone = request.args['phone']
    if 'lat' in request.args and 'lng' in request.args:
        lat = request.args['lat']
        lng = request.args['lng']
    else:
        if hasattr(ssl, '_create_unverified_context'):
            ssl._create_default_https_context = ssl._create_unverified_context
        location = geolocator.geocode(addr1 + " " + addr2)
        print(location.address)
        lat = location.latitude
        lng = location.longitude
        print(lat, lng)
    if 'file' in request.files:
        f = request.files['file']
        if f.filename == '':
            return jsonify({"file": "no name"})
        print("no name")
        if f and allowed_file(f.filename):
            print("i am here, final stage")
            filename = secure_filename(f.filename)
            f.save(
                os.path.join(app.config['UPLOAD_FOLDER'],
                             name + phone + filename))
            fname = name + phone + filename
            furl = url_for('rest_img', filename=name + phone + filename)
    else:
        fname = None
        furl = None
    restaurant = Restaurant(name=name,
                            address1=addr1,
                            address2=addr2,
                            menu_type=menu,
                            phone=phone,
                            has_delivery=delivery,
                            has_parking=park,
                            has_cards=card,
                            has_reservation=reservation,
                            has_terrace=terrace,
                            has_wifi=wifi,
                            offer=offer,
                            cost=cost,
                            lat=lat,
                            lng=lng,
                            image_filename=fname,
                            image_url=furl)
    db.session.add(restaurant)
    db.session.commit()
    return jsonify({'restaurant': {"id": restaurant.id}})
Exemple #18
0
 def testInsertEntity(self):
   restaurant = Restaurant()
   restaurant.put()
   self.assertEqual(1, len(Restaurant.query().fetch(2)))