Guest User

Ronnie

a guest
Feb 17th, 2010
1,107
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def EnterNew(self):
  2.  
  3. ings = []
  4.  
  5. recipename = ''
  6.  
  7. recipesource = ''
  8.  
  9. recipeserves = ''
  10.  
  11. instructions = ''
  12.  
  13. lastid = 0
  14.  
  15. resp = raw_input('Enter Recipe Title (Blank line to exit) -> ')
  16.  
  17. if resp != '' : # continue
  18.  
  19. if string.find(resp,"'"):
  20.  
  21. recipename = resp.replace("'","\'")
  22.  
  23. else:
  24.  
  25. recipename = resp
  26.  
  27. print "RecipeName will be %s" % recipename
  28.  
  29. resp = raw_input('Enter Recipe Source -> ')
  30.  
  31. if string.find(resp,"'"):
  32.  
  33. recipesource = resp.replace("'","\'")
  34.  
  35. else:
  36.  
  37. recipesource = resp
  38.  
  39. resp = raw_input('Enter number of servings -> ')
  40.  
  41. if string.find(resp,"'"):
  42.  
  43. recipeserves = resp.replace("'","\'")
  44.  
  45. else:
  46.  
  47. recipeserves = resp
  48.  
  49. print 'Now we will enter the ingredient list.'
  50.  
  51. cont = True
  52.  
  53. while cont == True:
  54.  
  55. ing = raw_input('Enter Ingredient ("0" to exit) -> ')
  56.  
  57. if ing != '0':
  58.  
  59. ings.append(ing)
  60.  
  61. else:
  62.  
  63. cont = False
  64.  
  65. resp = raw_input('Enter Instructions -> ')
  66.  
  67. instructions = resp
  68.  
  69. print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
  70.  
  71. print "Here's what we have so far"
  72.  
  73. print "Title: %s" % recipename
  74.  
  75. print "Source: %s" % recipesource
  76.  
  77. print "Serves: %s" % recipeserves
  78.  
  79. print "Ingredients:"
  80.  
  81. for x in ings:
  82.  
  83. print x
  84.  
  85. print "Instructions: %s" % instructions
  86.  
  87. print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
  88.  
  89. resp = raw_input("OK to save? (Y/n) -> ")
  90.  
  91. if string.upper(resp) != 'N':
  92.  
  93. connection=apsw.Connection("cookbook.db3")
  94.  
  95. cursor=connection.cursor()
  96.  
  97. # Write the Recipe Record
  98.  
  99. sql = 'INSERT INTO Recipes (name,servings,source) VALUES ("%s","%s","%s")' %(recipename,recipeserves,recipesource)
  100.  
  101. cursor.execute(sql)
  102.  
  103. # Get the new Recipe pkID
  104.  
  105. sql = "SELECT last_insert_rowid()"
  106.  
  107. cursor.execute(sql)
  108.  
  109. for x in cursor.execute(sql):
  110.  
  111. lastid = x[0]
  112.  
  113. print "last id = %s" % lastid
  114.  
  115. # Write the Instruction Record
  116.  
  117. for x in ings:
  118.  
  119. sql = 'INSERT INTO Ingredients (recipeID,ingredients) VALUES (%s,"%s")' % (lastid,x)
  120.  
  121. cursor.execute(sql)
  122.  
  123. # Write the Ingredients records
  124.  
  125. sql = 'INSERT INTO Instructions (recipeID,instructions) VALUES( %s,"%s")' %(lastid,instructions)
  126.  
  127. cursor.execute(sql)
  128.  
  129. # Prompt the user that we are done
  130.  
  131. print 'Done'
  132.  
  133. else:
  134.  
  135. print 'Save aborted'
RAW Paste Data