def opinion_post(): name = request.form["name"] title = request.form["title"] opinion = request.form["opinion"] create_opinion(name, title, opinion) identity = get_id(name, title, opinion) if "file" in request.files: image_file = request.files["file"] img_type = image_file.filename.split(".")[-1] if img_type in ALLOWED_EXTENSIONS: filename = secure_filename("saved_image_" + str(identity) + "." + img_type) saved_filename = os.path.join(app.config["UPLOAD_FOLDER"], filename) if ON_COMPUTER: touch(FULL_PATH + saved_filename) image_file.save(FULL_PATH + saved_filename) else: touch(saved_filename) image_file.save(saved_filename) else: raise AssertionError("Invalid Image type") img_url = saved_filename else: img_url = DEFAULT_IMAGE_URL change_url(identity, img_url) return redirect(url_for("hello_world"))
def classinfo(): if not session.has_key('user'): return redirect(url_for("about")) username=session['user'] name=database.get_name(username) osis=database.get_osis(username) digits=database.get_id(username) email=database.get_email(username) schedule=database.get_schedule(username) classes=database.get_class_info() if request.method=='GET': return render_template("class.html" ,name=name ,osis=osis ,digits=digits ,email=email ,classes=classes ,schedule=schedule ,get=True) if request.method=="POST": value=request.form['button'] value=value.split(" ") index=int(value[1])-1 validate=True if (str(value[0])=="set"): period=classes[index][0] clas=classes[index] schedule=database.get_schedule(username) if schedule[int(period)-1][1]=="free": database.set_period(username,period,clas) else: validate=False if (str(value[0])=="req"): req=classes[index] period=classes[index][0] if database.has_lunch(username,period) or l_equal(schedule[int(period)-1],req): validate=False else: database.post_request(username,req) return render_template("class.html" ,name=name ,osis=osis ,digits=digits ,email=email ,classes=classes ,schedule=schedule ,validate=validate)
def photo(update, context): data['code_id'] = db.get_id(data['tel_id']) code_id = data['code_id'] photo_file = update.message.photo[-1].get_file() file_path = f'photos/img_{code_id}.jpg' photo_file.download(file_path) # blob_form = convert_to_blob(file_path) # data['photo'] = blob_form res_reg = db.new_female_advertisement(data) if res_reg: text = """ ثبت آگهی شما تکمیل شده است و پس از تایید توسط ادمین منتشر خواهد شد """ else: text = """ متاسفانه ثبت آگهی شما با خطا مواجه شد، لطفا دوباره تلاش کنید """ ret = [[InlineKeyboardButton('بازگشت', callback_data='return_key')]] ret_key = InlineKeyboardMarkup(ret) update.message.reply_text(text, reply_markup=ret_key) return ConversationHandler.END
def edit(): if not session.has_key('user'): return redirect(url_for("about")) username=session['user'] email=database.get_email(username) osis=database.get_osis(username) digit=database.get_id(username) if request.method=='GET': return render_template("edit.html" ,username=username ,email=email ,osis=osis ,digit=digit ,loggedout=False) if request.method=='POST': if request.form['button']=='Edit': password=request.form['password'] email=request.form['email'] digit=request.form['digit'] osis=request.form['osis'] lunch=request.form['lunch'] schedule=database.get_schedule(username) current_lunch=database.get_lunch(username) pos=database.get_period(username,int(lunch))[1] if not (pos == 'free' or pos=='Cafe'): return render_template("edit.html" ,username=username ,email=email ,osis=osis ,digit=digit ,loggedout=False ,invalid=True) database.set_period(username,current_lunch,["","free","n/a","",""]) database.set_period(username,lunch,[str(lunch),"Cafe","Chi Kun Wang","ZLN5","0"+str(lunch)]) database.set_password(username,password) database.set_email(username,email) database.set_id(username,digit) database.set_osis(username,osis) return redirect(url_for('profile')) return redirect(url_for('edit'))
def profile(): if not session.has_key('user'): return redirect(url_for('about')) username=session['user'] name=database.get_name(username) osis=database.get_osis(username) digits=database.get_id(username) email=database.get_email(username) schedule=database.get_schedule(username) notif=database.get_notification(username) if request.method=='GET': return render_template("profile.html" ,name=name ,osis=osis ,digits=digits ,schedule=schedule ,email=email ,accept=notif["accept"] ,accepted=notif["accepted"] ) elif request.method=="POST": value=request.form["button"] value=value.split(" ") index=int(value[1])-1 if str(value[0])=="drop": schedule=database.get_schedule(username) clas=schedule[index] if not (clas[1]=="free" or clas[1]=="Cafe"): database.drop_period(username,clas[0]) schedule=database.get_schedule(username) return render_template("profile.html" ,name=name ,osis=osis ,digits=digits ,schedule=schedule ,email=email ,accept=notif["accept"] ,accepted=notif["accepted"] )
def visit(username=""): if not session.has_key('user'): return redirect(url_for('about')) me=session['user'] if str(username)==str(me): return redirect(url_for('profile')) name=database.get_name(username) osis=database.get_osis(username) digits=database.get_id(username) email=database.get_email(username) schedule=database.get_schedule(username) notif=database.get_notification(username) if request.method=='GET': return render_template("visit.html" ,name=name ,osis=osis ,digits=digits ,schedule=schedule ,email=email ,accept=notif["accept"] ,accepted=notif["accepted"] )
def detect(self, path, student_name, course_name, block_id): image_string = self.decode_json(path, course_name, block_id, student_name) frame = self.decode_image(image_string) log.info("Line 2") # Load the Haar-Cascade and # retrieve Cascade to detect eyes from the same eye_cascade_path = "/edx/app/edxapp/venvs/proctor/lib/python2.7/site-packages/suspicious_images/haarcascade_eye.xml" eye_cascade = cv2.CascadeClassifier(eye_cascade_path) # A boolean variable which stores if the person was cheating in the frame cheat_bool = 0 # reduce the noise in image by blurring and the blurred image to # original image so as to subtract local mean color image. blurred = cv2.GaussianBlur(frame, (21, 21), 0) weight_frame = cv2.addWeighted(frame, 1.75, blurred, -0.5, 0) # Equalise histogram to improve the contrast (Removing glare) # - Need to convert it to YUV image yuv = cv2.cvtColor(frame, cv2.COLOR_BGR2YUV) yuv[:, :, 0] = cv2.equalizeHist(yuv[:, :, 0]) # reconvert the image to grayscale to be feeded to Clahe bgr_frame = cv2.cvtColor(yuv, cv2.COLOR_YUV2BGR) gray = cv2.cvtColor(bgr_frame, cv2.COLOR_BGR2GRAY) # again apply Contrast Limited Adaptive Histogram Equalisation # can only work on grayscale images clahe = cv2.createCLAHE(clipLimit=40.0, tileGridSize=(8, 8)) gray = clahe.apply(gray) # load the haar-cascade to get the region of interest - eye_region eyes = eye_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=3) # How many times to load the haar-cascade to increase effectiveness sample_tries = 2 while sample_tries: for (x, y, width, height) in eyes: cv2.rectangle(frame, (x, y), (x + width, y + height), (0, 255, 0), 2) break sample_tries -= 1 # if already eyes are recongnized - break out of loop if len(eyes): break # If no eye_region is found, that would mean that either the person's face is not # straightly oriented in front of webcam or he is cheating - In any case mark as suspicious if len(eyes) == 0: cheat_bool = 1 else: # crop the right portion of the eyes to enable accurate detection of pupil, # blur that region again to reduce noise. gray_cropped_right = gray[eyes[0][1]:eyes[0][1] + eyes[0][3], eyes[0][0] + eyes[0][2] / 2:eyes[0][0] + eyes[0][2]] cv2.GaussianBlur(gray_cropped_right, (3, 3), 16) # use HoughCircles method to detect the circular shape in right part of eye (cropped earlier) circles_right = cv2.HoughCircles(gray_cropped_right, cv2.cv.CV_HOUGH_GRADIENT, dp=5, minDist=60, param1=30, param2=10, minRadius=5, maxRadius=20) try: # find the pupil-positions corresponding to the circle region pupil_position = np.uint16(np.around(circles_right)) # form a small circle around the pupil-position for (a, b, radius) in pupil_position[0]: cv2.circle(frame, (a + x + width / 2, b + y), 2, (255, 0, 0), 2) except: pass # If the user is found to be cheating, the corresponding images can be saved in the directory if cheat_bool == 1: # TODO Increament this variable in database using some course_name/student_name student_id = database.get_id(student_name) database.update_table(student_id, course_name, "img_count", 1) path_img = self.get_path(path, course_name, block_id, student_name) + "/susp_img" if not os.path.exists(path_img): os.makedirs(path_img) path_img += "/" cv2.imwrite(path_img + str(len(os.listdir(path_img))) + ".jpg", frame)
def tradingfloor(): if not session.has_key('user'): return redirect(url_for("about")) username=session['user'] name=database.get_name(username) osis=database.get_osis(username) digits=database.get_id(username) email=database.get_email(username) database.refresh_floor() floor=database.get_floor() if request.method=='GET': return render_template("trading.html" ,name=name ,osis=osis ,digits=digits ,floor=floor ,email=email ,validate=False) if request.method=='POST': value=request.form["button"] value=value.split(" ") index=int(value[1])-1 req=floor[index]["request"] period=int(req[0])-1 acceptername=username postername=floor[index]['username'] schedule=database.get_schedule(username)[period] validate=False myself=False illegaldel=False try: if not str(postername)==str(username): if value[0]=="accept": if l_equal(req,schedule): database.accept_request(postername,acceptername,req) return redirect(url_for("tradingfloor")) else: validate=True elif value[0]=="delete": validate=True myself=False illegaldel=True else: if value[0]=="accept": validate=True myself=True else: database.remove_request(username,req) database.refresh_floor() floor=database.get_floor() return render_template("trading.html" ,name=name ,osis=osis ,digits=digits ,email=email ,floor=floor ,validate=validate ,myself=myself ,illegaldel=illegaldel) except Exception: return render_template("trading.html" ,name=name ,osis=osis ,digits=digits ,email=email ,floor=floor ,validate=True)