File size: 1,006 Bytes
3bc2a85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sqlite3
import pandas as pd

DB_NAME = "menuvision.db"

def init_db():
    conn = sqlite3.connect(DB_NAME)
    c = conn.cursor()
    # Create Tables
    c.execute('''CREATE TABLE IF NOT EXISTS restaurants 
                 (id INTEGER PRIMARY KEY, name TEXT, location TEXT, owner TEXT)''')
    conn.commit()
    conn.close()

def add_restaurant(name, location, owner):
    try:
        conn = sqlite3.connect(DB_NAME)
        c = conn.cursor()
        c.execute("INSERT INTO restaurants (name, location, owner) VALUES (?, ?, ?)", (name, location, owner))
        conn.commit()
        conn.close()
        return f"Success: Restaurant '{name}' added!"
    except Exception as e:
        return f"Error: {e}"

def search_restaurants(query):
    conn = sqlite3.connect(DB_NAME)
    # Simple SQL query to find matches
    sql = f"SELECT name, location, owner FROM restaurants WHERE name LIKE '%{query}%' OR location LIKE '%{query}%'"
    df = pd.read_sql_query(sql, conn)
    conn.close()
    return df