Beispiel #1
0
    def handleSessionCreate(self):
        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)

        email = data['email'][0]
        pw = data['password'][0]

        #send to the database
        db = RecipesDB()

        user = db.getUserByEmail(email)
        if user == None:
            #failure
            self.handle401()
        else:
            if bcrypt.verify(pw, user['encrypted_password']):
                #YAY
                self.session["userID"] = user["id"]
                self.send_response(201)
                self.end_headers()
            else:
                #failure
                self.handle401()
Beispiel #2
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 #3
0
 def handleSessionRetrieve(self):
     if "userID" in self.session:
         # db = UsersDB()
         db = RecipesDB()
         user = db.getUser(self.session["userID"])
         self.send_response(200)
         self.send_header("Content-type", "application/json")
         self.end_headers()
         self.wfile.write(bytes(json.dumps(user), "utf-8"))
     else:
         self.handle401()
Beispiel #4
0
    def handleRecipeList(self):
        # todo: copy this to all receipe methods
        if "userID" not in self.session:
            self.handle401()
            return

        self.send_response(200)
        self.send_header("Content-Type", "application/json")
        self.end_headers()
        #receive message here
        db = RecipesDB()
        recipes = db.getRecipes()

        self.wfile.write(bytes(json.dumps(recipes), "utf-8"))
Beispiel #5
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 #6
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 #7
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
Beispiel #8
0
    def handleRecipeCreate(self):
        if "userID" not in self.session:
            self.handle401()
            return

        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]

        #send to the database
        db = RecipesDB()
        db.createRecipe(name, ingredients, instructions, cooktime, preptime)

        self.send_response(201)
        self.end_headers()
Beispiel #9
0
    def handleUserCreate(self):
        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)

        fname = data['fname'][0]
        lname = data['lname'][0]
        email = data['email'][0]
        password = data['password'][0]

        encrypted_password = bcrypt.hash(password)

        #send to the database
        # db = UsersDB()
        db = RecipesDB()
        if db.getUserByEmail(email) == None:
            db.createUser(fname, lname, email, encrypted_password)
            self.send_response(201)
            self.end_headers()
            #alert("You have successfully signed up")
        else:
            self.handle422()
Beispiel #10
0
def grabSite(grb, module, j_range):
      range = grb.getRange()
      print "thread %s started with range %s" % (module, str(j_range))
      range = range[ j_range[0]* len(range)/100 : j_range[1]* len(range)/100 ]
      recipes_left = len(range)
      db_name = module + '_'+'-'.join([str(x) for x in j_range ])  + '.sqlite'
      db = RecipesDB(db_name, module)
      #range = [782]
      for id in range:
         if done:
            break
         if id <= db.getGreatestID():
            recipes_left-=1
            continue
         print "parsing %d from %s, %d left" % (id, module, recipes_left)
         recipes_left-=1
         if grb.doParse(id):
            db.pushRecipe(id, grb.getCaption(), grb.getManual(), grb.getIngridients(), grb.getUrl(), grb.getCategory())
         time.sleep(5)
         
         
      db.commit()
      print "thread %s exited" % module