def home(): #food = [] food = getAllFoods() FullLength = len(food) length1 = len(food) g.db = connect_db() #g.db.execute("INSERT INTO entries(food,attributes) VALUES('chicken')") for x in range(FullLength): for y in range(len(food[x])): if len(food[x][y][1]) == "none" : g.db.execute("INSERT INTO entries(food,attributes) VALUES(?,?)",[food[x][y][0],food[x][y][1]]) g.db.commit() else: g.db.execute("INSERT INTO entries(food,attributes) VALUES(?,?)",[food[x][y][0],food[x][y][1]]) g.db.commit() g.db = connect_db() #Get everything from entries cur = g.db.execute('select * from entries') #Create dictionary using list comprehension entries = [dict(food=row[1], attributes = row[2]) for row in cur.fetchall()] #Returns the html to user return render_template('index.html', entries = entries)
def home(): #food = [] food = getAllFoods() FullLength = len(food) length1 = len(food) g.db = connect_db() #g.db.execute("INSERT INTO entries(food,attributes) VALUES('chicken')") for x in range(FullLength): for y in range(len(food[x])): if len(food[x][y][1]) == "none": g.db.execute( "INSERT INTO entries(food,attributes) VALUES(?,?)", [food[x][y][0], food[x][y][1]]) g.db.commit() else: g.db.execute( "INSERT INTO entries(food,attributes) VALUES(?,?)", [food[x][y][0], food[x][y][1]]) g.db.commit() g.db = connect_db() #Get everything from entries cur = g.db.execute('select * from entries') #Create dictionary using list comprehension entries = [dict(food=row[1], attributes=row[2]) for row in cur.fetchall()] #Returns the html to user return render_template('index.html', entries=entries)
def populate_Db(): with app.app_context(): allHalls = getAllFoods() numDininghalls = len(allHalls) #We open a database connection g.db = connect_db() for aHall in range(numDininghalls): for aFood in range(len(allHalls[aHall])): # g.db.execute("INSERT INTO entries(food,hall) VALUES(?,?)",[allHalls[aHall][aFood][0],aHall]) print("LOKOOKOKOKOK") print(allHalls[aHall][aFood][1]) #Store attributes as one string to later be broken into components attString = '' for att in allHalls[aHall][aFood][1]: attString +=(att+', ') #Removed excess comma allAttString = attString[:-2] print("HEKFSDGSDGSDFGSD") print(allAttString) g.db.execute("INSERT INTO entries(food,attributes,hall) VALUES(?,?,?)",[allHalls[aHall][aFood][0],allAttString,aHall]) # g.db.execute("INSERT INTO entries(food) VALUES(?)",[allHalls[aHall][aFood][0]]) g.db.commit() # if not(len(allHalls[aHall][aFood][1]) == 0): # print("this was not zero!!") #for att in range(len(allHalls[aHall][aFood][1])): # #Dont dont attach 'empty' attributes to a food # print(allHalls[aHall][aFood][1]) # # if (len(allHalls[aHall][aFood][1]) == 0): # # print("This was empty!!") #g.db.execute("INSERT INTO entries(attributes) VALUES(?)",[allHalls[aHall][aFood][1][att]]) #g.db.commit() # else: # g.db.execute("INSERT INTO entries(food,hall) VALUES(?,?)",[allHalls[aHall][aFood][0],aHall]) # g.db.commit() print('Close database!') g.db.close()
MAIL_USE_SSL=True, MAIL_USERNAME = '******', MAIL_PASSWORD = '******' ) port = int(os.environ.get("PORT",5000)) #Create mail object mail = Mail(app) app.config.from_object(__name__) app.config["DEBUG"] = True app.database = "WhatsCookin\'.db" food = [] food = getAllFoods() FullLength = len(food) length1 = len(food) #Create variable to reference database file app.database = "WhatsCookin\'.db" #Creates a connection def connect_db(): return lite.connect(app.database) #Creates the database if it doesnt exist def init_db():
MAIL_SERVER='smtp.gmail.com', MAIL_PORT=465, MAIL_USE_SSL=True, MAIL_USERNAME='******', MAIL_PASSWORD='******') port = int(os.environ.get("PORT", 5000)) #Create mail object mail = Mail(app) app.config.from_object(__name__) app.config["DEBUG"] = True app.database = "WhatsCookin\'.db" food = [] food = getAllFoods() FullLength = len(food) length1 = len(food) #Create variable to reference database file app.database = "WhatsCookin\'.db" #Creates a connection def connect_db(): return lite.connect(app.database) #Creates the database if it doesnt exist def init_db():