Commit 5b211b4a authored by Arhan Banerjee's avatar Arhan Banerjee
Browse files

Continued working on SQL commands

parent a72ac469
......@@ -5,9 +5,9 @@ from datetime import datetime
db = mysql.connect(
host = "marmoset04.shoshin.uwaterloo.ca",
user = "",
passwd = ""
host = "marmoset03.shoshin.uwaterloo.ca",
user = "a39baner",
passwd = "Catcatcat11!"
)
......@@ -59,6 +59,49 @@ def create_recipe(user_id):
ingredients = input("Enter ingredients seperated by commas: ")
ingredient_list = splitter(ingredients, False)
sql_command_selectingmax = "SELECT MAX(recipe_id) FROM recipes;\n"\
"SELECT MAX(ingredient_id) FROM ingredients;\n"\
"SELECT MAX(tag_id) FROM tag;\n"\
"@max_recipe_id += 1;\n"
sql_command_insert = "INSERT INTO recipes ( recipe_id, name, minutes, contributor_id, date_submitted, calories,"\
"fat, sugar, sodium, protein, sat_fat, carbohydrates, n_steps, steps, description ) VALUES ( @max_recipe_id,"\
+ recipe_name + ", " + minutes_taken + ", " + user_id + ", " + date_submitted + ", " + calories + ", "\
+ fat + ", " + sugar + ", " + sodium + ", " + protein + ", " + saturated_fat + ", " + carbs + ", "\
+ steps_count + ", " + steps + ", " + description + ");\n"
for i in ingredient_list:
sql_command_ingredient = "SELECT ingredient_id FROM ingredients WHERE name = " + i
#cursor.execute(sql_command_ingredient)
#ingredients_id = cursor.fetchall()
if ingredients_id != "NULL":
sql_command_ingredient = "INSERT INTO recipe_ingredients ( recipe_id, ingredient_id ) VALUES ( @max_recipe_id, " + ingredients_id + " );\n"
else:
sql_command_ingredient = "@max_ingredient_id += 1;\n"\
"INSERT INTO ingredients (ingredient_id, name) VALUES (@max_ingredient_id, " + i + ");\n"
#cursor.execute(sql_command_ingredient)
sql_command_ingredient = "INSERT INTO recipe_ingredients (recipe_id, ingredient_id) VALUES (@max_recipe_id, @max_ingredient_id);"
#cursor.execute(sql_command_ingredient)
for t in tag_list:
sql_command_tag = "SELECT tag_id FROM tag WHERE name = " + t
#cursor.execute(sql_command_tag)
#tags_id = cursor.fetchall()
if tags_id != "NULL":
sql_command_tag = "INSERT INTO recipe_tag (recipe_id, tag_id) VALUES (@max_recipe_id, " + tags_id + ");"
else:
sql_command_tag = "@max_tag_id += 1;\n"\
"INSERT INTO ingredients (tag_id, name) VALUES (@max_tag_id, " + t + ");\n"
#cursor.execute(sql_command_tags)
sql_command_tag = "INSERT INTO recipe_tag (recipe_id, tag_id) VALUES (@max_recipe_id,@max_tag_id);\n"
#cursor.execute(sql_command_tags)
def create_review(user_id):
# user can only leave one review per recipe?
......@@ -69,6 +112,8 @@ def create_review(user_id):
rating = input("Enter a rating for this review (An integer between 0 and 5): ")
review_text = input("Enter any comments about the recipe: ")
sql_create_review_command = ""
def edit_recipe(user_id):
......@@ -187,7 +232,25 @@ def search():
elif(search_command == "Recipe Name"):
search_attribute = input("Enter part or full recipe name to search by: ")
sql_command = "SELECT * FROM recipes WHERE Name LIKE '%" + search_attribute + "%';"
print(sql_command)
#print(sql_command)
cursor.execute(sql_command)
tables = cursor.fetchall()
if (len(tables) != 0):
for entry in tables:
print("\n***************\n")
print("Recipe Name: " + entry[0])
print("Recipe ID: " + str(entry[1]))
print("Minutes Taken: " + str(entry[2]))
print("Contributor ID: " + str(entry[3]))
print("Steps: " + entry[13])
print("Description: " + entry[14])
print("\n***************\n")
else:
print("\n***************\n")
print("No recipes found")
print("\n***************\n")
# SQL code
elif(search_command == "Minutes"):
search_attribute = input("Enter max number of minutes taken for a recipe: ")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment