<jupyter_start><jupyter_text>Take Home Leftcontroller for food leftovers. python functions.<jupyter_code>import sqlite3
import arrow
from passlib.apps import custom_app_context as pwd_context
def createReviewDB(namedb):
    conn = sqlite3.connect('{}.db'.format(namedb))
    c = conn.cursor()

    # Create table
    c.execute('''CREATE TABLE reviews (myid integer, forid integer, foodid integer, rating integer, comments text, datetime text)''')

    
def createReview(myid, forid, idfood, rating, comments):
    timnow = arrow.utcnow()
    
    #str(timnow.datetime)
    
    conn = sqlite3.connect('foodentry.db')
    c = conn.cursor()
    c.execute("INSERT INTO reviews VALUES ('{}', '{}', '{}', '{}', '{}', '{}')".format(myid, forid, idfood, rating, 
                                                                              comments, 
                                                                              str(timnow.datetime)))
    
    conn.commit()

    # We can also close the connection if we are done with it.
    # Just be sure any changes have been committed or they will be lost.
    conn.close()
def lookupReviews():
    conn = sqlite3.connect('foodentry.db')
    c = conn.cursor()
    allfod = c.execute('SELECT * FROM reviews')
    return(allfod.fetchall())
    
    
def lookupMyReviews(myid):
    conn = sqlite3.connect('foodentry.db')
    c = conn.cursor()
    allfod = c.execute('SELECT * FROM reviews WHERE myid OR forid = {}'.format(myid))
    return(allfod.fetchall())
#LookupMyReviews(1)
#createreviewdb('foodentry')
#createreview(1, 2, 5, 'super good food')
#loopupreviews()
def createUserDB(namedb):
    conn = sqlite3.connect('{}.db'.format(namedb))
    c = conn.cursor()

    # Create table
    c.execute('''CREATE TABLE users
             (email text, password text, userid integer, image text, name text, location text)''')

    
def createUser(email, password, image, name, location):
    conn = sqlite3.connect('foodentry.db')
    c = conn.cursor()
    hashpass = pwd_context.hash(password)

    c.execute("INSERT INTO users VALUES ('{}', '{}', '{}', '{}', '{}', '{}')".format(name, 
                                                                              hashpass, returnCountUsers() + 1, image, 
                                                                              name, 
                                                                              location))
    
    conn.commit()

    # We can also close the connection if we are done with it.
    # Just be sure any changes have been committed or they will be lost.
    conn.close()
    returnCountUsers()
def createFoodDB(namedb):
    conn = sqlite3.connect('{}.db'.format(namedb))
    c = conn.cursor()

    # Create table
    c.execute('''CREATE TABLE foods
             (name text, foodid integer, image text, datecook text, dateexpire text, 
             ingredients text, location text, myid integer, soldstatus integer)''')

    
def makeFoodEntry(name, image, datecooked, expiredate,
                 ingredients, location, myid):
    conn = sqlite3.connect('foodentry.db')
    c = conn.cursor()
    c.execute("INSERT INTO foods VALUES ('{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '0')".format(name, 
                                                                              returnCountFood() + 1, image, 
                                                                              datecooked, 
                                                                              expiredate, ingredients, location, myid))
    
    conn.commit()

    # We can also close the connection if we are done with it.
    # Just be sure any changes have been committed or they will be lost.
    conn.close()

    return({'name' : name, 'foodid' : returnCountFood() + 1, 'image' : image, 'datecooked' : datecooked,
           'expiredate' : expiredate, 'ingredients' : ingredients, 'location' : location, 'myid' : myid})
def returnFoods():
    conn = sqlite3.connect('foodentry.db')
    c = conn.cursor()
    allfod = c.execute('SELECT * FROM foods')
    return(allfod.fetchall())
    
def returnCountFood():
    conn = sqlite3.connect('foodentry.db')
    c = conn.cursor()
    allfod = c.execute('SELECT count(*) FROM foods')
    return(allfod.fetchall()[0][0])
    
def returnCountUsers():
    conn = sqlite3.connect('foodentry.db')
    c = conn.cursor()
    allfod = c.execute('SELECT count(*) FROM users')
    return(allfod.fetchall()[0][0])
#returncountusers()
def returnUsers():
    conn = sqlite3.connect('foodentry.db')
    c = conn.cursor()
    allfod = c.execute('SELECT * FROM users')
    return(allfod.fetchall())
    
def returnReviews():
    conn = sqlite3.connect('foodentry.db')
    c = conn.cursor()
    allfod = c.execute('SELECT * FROM reviews')
    return(allfod.fetchall())
    
#returncountfood()
def filterFoods(searchfood):
    conn = sqlite3.connect('foodentry.db')
    c = conn.cursor()
    allfod = c.execute('SELECT * FROM foods WHERE foodid = {}'.format(searchfood))
    return(allfod.fetchall())
    
#filterfoods(2)
def makeFoodRequest(whatfood):
    return('you requested {}'.format(whatfood))
#createfoodb('foodentry')
#makefoodentry('pasta', 'me.com/img.png', '04/12/1999', '06/12/1999',
#                 'pork, pasta')
#returnfoods()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13616701147263494, 'fraction_numerical': 0.008275343238668423, 'mean_word_length': 2.213293051359517, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '260735', 'license': 'MIT', 'n_tokens_mistral': 1567, 'n_tokens_neox': 1493, 'n_words': 385, 'path': 'foodgiving/takehomeleft.ipynb', 'repo_name': 'artcontrol/foodgiving', 'size': '5317'}