Beispiel #1
0
    def handleRecipeReplace(self, recipe_id):
        if "userID" not in self.session:
            self.handle401()
            return

        db = RecipesDB()
        recipe = db.getRecipe(recipe_id)
        print("testing replace", recipe_id)
        if recipe == None:
            self.handleNotFound()
        else:
            length = self.headers["Content-length"]
            #ready body data from client
            body = self.rfile.read(int(length)).decode("utf-8")
            #parse the body into a dictionary with values of arrays
            data = parse_qs(body)

            name = data['name'][0]
            ingredients = data['ingredients'][0]
            instructions = data['instructions'][0]
            cooktime = data['cooktime'][0]
            preptime = data['preptime'][0]
            db.replaceRecipe(name, ingredients, instructions, cooktime,
                             preptime, recipe_id)
            self.send_response(200)
            self.end_headers()
            self.wfile.write(bytes("<h1> Recipe Deleted</h1>", "utf-8"))
Beispiel #2
0
    def handleRecipeDelete(self, recipe_id):
        if "userID" not in self.session:
            self.handle401()
            return

        db = RecipesDB()
        recipe = db.getRecipe(recipe_id)
        print("testing delete", recipe_id)
        if recipe == None:
            self.handleNotFound()
        else:
            db.deleteRecipe(recipe_id)
            self.send_response(200)
            self.end_headers()
            self.wfile.write(bytes("<h1> Recipe Deleted</h1>", "utf-8"))
Beispiel #3
0
    def handleRecipeRetrieve(self, recipe_id):
        if "userID" not in self.session:
            self.handle401()
            return

        db = RecipesDB()
        recipe = db.getRecipe(recipe_id)
        print("testing", recipe)
        if recipe == None:
            self.handleNotFound()
        else:
            myjson = json.dumps(recipe)
            self.send_response(200)
            self.send_header("Content-Type", "application/json")
            self.end_headers()
            self.wfile.write(bytes(myjson, "utf-8"))
Beispiel #4
0
def MainThread():
   global done
   db = RecipesDB(db_name)
   recipes =  db.getRecipeIDs()

   last_recipe = 0
   if len( sys.argv ) > 1:
      last_recipe = recipes.index( int (sys.argv[1]) )  +  1 
      recipes = recipes[last_recipe:]
   for i in recipes:
      ID = i
      print "sending %d" % ID
      recipe = db.getRecipe(ID)
      req = urllib2.Request(url, json.dumps(recipe))
      response = urllib2.urlopen(req)
      print "Done"
      if done:
         return