Exemple #1
0
def add_location():
    content = request.get_json()
    r = Restaurant(content['id'], content['title'], content['coords']['latitude'], content['coords']['longitude'], content['google_ratings'], content['types'])
    db_session.add(r)
    db_session.commit()
    db_session.remove()
    return 'success'
def select(restaurant_id):
    sql = "SELECT * FROM restaurants WHERE id = %s"
    values = [restaurant_id]
    result = run_sql(sql, values)[0]
    restaurant = Restaurant(result['name'], result['address'],
                            result['phone_number'], result['availability'],
                            result['cuisine_id'], result['id'])
    return restaurant
Exemple #3
0
def new_restaurant():
    if request.method == 'POST':
        newRestaurant = Restaurant(name=request.form['name'],
                                   user_id=login_session['user_id'])
        session.add(newRestaurant)
        flash('New Restaurant %s Successfully Created' % newRestaurant.name)
        session.commit()
        return redirect(url_for('restaurant.show_restaurants'))
    else:
        return render_template('newRestaurant.html')
def select_all():
    restaurants = []

    sql = "SELECT * FROM restaurants"
    results = run_sql(sql)

    for row in results:
        cuisine = cuisine_repository.select(row['cuisine_id'])
        restaurant = Restaurant(row['name'], row['address'],
                                row['phone_number'], row['availability'],
                                cuisine, row['id'])
        restaurants.append(restaurant)
    return restaurants
Exemple #5
0
def update_restaurant(restaurant_id):
    restaurant = request.form["restaurant"]
    cuisine_id = request.form["cuisine_id"]
    address = request.form["address"]
    phone_number = request.form["phone_number"]
    availability = request.form["availability"]

    cuisine = cuisine_repository.select(cuisine_id)

    update_restaurant = Restaurant(restaurant, address, phone_number,
                                   availability, cuisine, restaurant_id)
    restaurant_repository.update(update_restaurant)
    return redirect("/restaurants")
Exemple #6
0
def add():
    form = RestaurantForm()
    model = Restaurant()
    if hasattr(request, 'POST'):
        form = RestaurantForm(request.POST)

        if form.validate():
            form.populate_obj(model)
            db.session.add(model)
            db.session.commit()
            flash("Restaurant added")
            return redirect(url_for("index"))

    return render_template("restaurant_add.html", form=form)
Exemple #7
0
def create_restaurant():
    name = request.form['name']
    cuisine_id = request.form['cuisine_id']
    address = request.form['address']
    phone_number = request.form['phone_number']
    availability = request.form['availability']

    cuisine = cuisine_repository.select(cuisine_id)

    new_restaurant = Restaurant(name, address, phone_number, availability,
                                cuisine)

    restaurant_repository.save(new_restaurant)
    return redirect('/restaurants')
Exemple #8
0
def create_restaurant(
        name, description, category_id, phone, address, city, country
):
    restaurant = Restaurant(
        name=name,
        description=description,
        category_id=category_id,
        phone=phone,
        address=address,
        city=city,
        country=country,
        addtime=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    )
    session.add(restaurant)
    session.commit()
    return {
        'restaurant_id': restaurant.restaurant_id,
        'success': 1,
        'message': 'create successfully.'
    }
def save_restaurant(request):
    restaurant = Restaurant(name=request.form['rest_name'])
    add_restaurant(restaurant)
Exemple #10
0
customer1 = Customer("Jenken", "1 Street Name", "Card", "07123456789",
                     "Delivery")
customer_repository.save(customer1)
customer1 = Customer("Jenken2", "2 Street Name", "Card", "07123456789",
                     "Delivery")
customer_repository.save(customer1)

chinese = Cuisine("Chinese")
cuisine_repository.save(chinese)
japanese = Cuisine("Japanese")
cuisine_repository.save(japanese)
fast_food = Cuisine("Fast Food")
cuisine_repository.save(fast_food)

mcdonalds = Restaurant("McDonalds", "137 Princes St", "01312263872", True,
                       fast_food)
restaurant_repository.save(mcdonalds)
kfc = Restaurant("KFC", "36 Nicolson St", "01316629524", True, fast_food)
restaurant_repository.save(kfc)

cheeseburger = Dish("Cheeseburger", 0.99, "A burger with cheese", mcdonalds)
dish_repository.save(cheeseburger)
doublecheeseburger = Dish("Double Cheeseburger", 1.99,
                          "A double burger with cheese", mcdonalds)
dish_repository.save(doublecheeseburger)
triplecheeseburger = Dish("Triple Cheeseburger", 2.99,
                          "A triple burger with cheese", mcdonalds)
dish_repository.save(triplecheeseburger)
quarterpounder = Dish("Quarter Pounder", 1.99,
                      "A burger that is a quarter of a pound", mcdonalds)
dish_repository.save(quarterpounder)
              str(14.421809 + j / 100))
        for k in range(0, len(places)):
            ident = places[k]['id']
            result_proxy = c.execute(
                "SELECT * FROM restaurants WHERE id = :id", {'id': ident})
            result = result_proxy.fetchall()
            if len(result) != 0:
                print("Row with id: " + ident + " already exists")
                continue
            x = places[k]['geometry']['location']['lat']
            y = places[k]['geometry']['location']['lat']
            name = places[k]['name']
            if places[k].__contains__('rating'):
                rating = places[k]['rating']
            types = ','.join(places[k]['types'])
            restaurant_list.append(Restaurant(ident, name, x, y, rating,
                                              types))

restaurant_dictionary = dict()
for restaurant in restaurant_list:
    if not restaurant_dictionary.__contains__(restaurant.id):
        restaurant_dictionary[restaurant.id] = restaurant

for key in restaurant_dictionary.keys():
    print(restaurant_dictionary[key].name)

print(len(restaurant_dictionary))

for key in restaurant_dictionary.keys():
    A = restaurant_dictionary[key]
    c.execute(
        """
# Create database.
create_db()

# Create dummy user
User1 = User(
    name="Robo Barista",
    email="*****@*****.**",
    picture=
    'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png'
)
session.add(User1)
session.commit()

# Menu for UrbanBurger
restaurant1 = Restaurant(user_id=1, name="Urban Burger")

session.add(restaurant1)
session.commit()

menuItem2 = MenuItem(
    user_id=1,
    name="Veggie Burger",
    description="Juicy grilled veggie patty with tomato mayo and lettuce",
    price="$7.50",
    course="Entree",
    restaurant=restaurant1)

session.add(menuItem2)
session.commit()
Exemple #13
0
db = DatabaseController()
session = db.get_session()

cities = sorted(session.query(City).all(), key=lambda x: x.population, reverse=True)

for city in cities:
    nearby = yc.get_nearby_restaurants_latlong(city.latitude, city.longitude)
    for rest in nearby:
        name = rest['name']
        lat = rest['coordinates']['latitude']
        lng = rest['coordinates']['longitude']
        website = rest['url']
        rating = rest['rating']
        cuisine = rest['categories'][0]['title']  # fix later to include all
        image = rest['image_url']
        pricing = ''
        try:
            # some places choose not to show prices
            pricing = rest['price']
        except:
            pass

        entry = Restaurant(name=name, latitude=lat, longitude=lng,
                           website=website, rating=rating, cuisine=cuisine,
                           pricing=pricing, image=image)
        try:
            session.add(entry)
            session.commit()
        except:  # we have enough data to ignore bad data
            session.rollback()
Exemple #14
0
def index():
    obj = Restaurant().query.all()
    return render_template("restaurant_list.html", obj=obj)