def list_users(): userlist = users.get_all_users() if users.is_admin(): mod_rights = True else: mod_rights = False return render_template("users_list.html", userlist=userlist, mod_rights=mod_rights)
def do_GET(self): self._set_headers(200) response = {} parsed = self.parse_url(self.path) if len(parsed) == 2: (resource, id) = parsed if resource == "latest_post": response = f"{get_latest_post()}" if resource == "posts": if id is not None: response = f"{get_single_post(id)}" else: response = f"{get_all_posts()}" if resource == "users" and id is None: response = get_all_users() if resource == "categories": if id is not None: response = f"{get_single_category(id)}" else: response = f"{get_all_categories()}" if resource == "comments": if id is not None: response = f"{get_single_comment(id)}" else: response = f"{get_all_comments()}" if resource == "tags": if id is not None: response = f"{get_single_tag(id)}" else: response = f"{get_all_tags()}" elif len(parsed) == 3: (resource, key, value) = parsed if key == "email" and resource == "users": response = get_user_by_email(value) if resource == "posts": if key == "category_id": response = get_posts_by_category_id(value) if key == "user_id": response = f"{get_posts_by_user_id(value)}" if key == "post_id" and resource == "post_tags": response = get_post_tags_by_post_id(value) if key == "post_id" and resource == "comments": response = get_comment_by_post(value) self.wfile.write(response.encode())
def do_GET(self): response = {} parsed = self.parse_url(self.path) if len(parsed) == 2: (resource, id) = self.parse_url(self.path) if resource == "categories": if id is not None: response = get_single_category(id) else: response = get_all_categories() elif resource == "users": if id is not None: response = get_single_user(id) else: response = get_all_users() elif resource == "tags": if id is not None: response = get_single_tag(id) else: response = get_all_tags() elif resource == "posts": if id is not None: response = get_single_post(id) else: response = get_all_posts() # elif resource == "otherResource": # ... elif len(parsed) == 3: (resource, key, value) = parsed if resource == "posts" and key == "user_id": response = get_posts_by_user_id(value) if resource == "post_tags" and key == "post_id": response = get_postTag_by_post_id(value) if resource == "posts" and key == "category_id": response = get_posts_by_category_id(value) if resource == "comments" and key == "post_id": response = get_comments_by_post_id(value) # if key == "yourKey" and resource == "yourResource": # response = get_yourResource_by_yourKey(value) # ... if response == False: self._set_headers(404) else: self._set_headers(200) self.wfile.write(f"{response}".encode())
def usermanagement(): if "user_id" not in session: return redirect("/") if session["role"] != "admin": return render_template( "error.html", message="Sinulla ei ole oikeuksia tälle sivulle.") return render_template( "usermanagement.html", users=users.get_all_users())
def do_GET(self): self._set_headers(200) response = {} # Parse URL and store entire tuple in a variable parsed = self.parse_url(self.path) if len(parsed) == 2: (resource, id) = parsed if resource == "categories" and id is None: response = get_categories() if resource == "tags": response = get_tags() if resource == "reactions": response = get_reactions() if resource == "tagPosts" and id is None: response = get_tagPosts() if resource == "subscriptions" and id is None: response = get_subscriptions() if resource == "posts": if id is not None: response = get_single_post(id) else: response = get_all_posts() if resource == "tagPosts" and id is None: response = get_tagPosts() if resource == "reactionPosts" and id is None: response = get_reactionPosts() if resource == "users": if id is not None: response = get_single_user(id) else: response = get_all_users() elif len(parsed) == 3: (resource, key, value) = parsed if key == "email" and resource == "users": response = get_user_by_email(value) if key == "category_id" and resource == "posts": response = get_posts_by_category_id(value) if key == "user_id" and resource == "posts": response = get_posts_by_user_id(value) if key == "tag_id" and resource == "posts": response = get_posts_by_tag_id(value) if key == "post_id" and resource == "tags": response = get_single_post_tags(value) self.wfile.write(response.encode())
def update_all_collections(self): if not (current_user.username == "admin"): return jsonify({ "success": False, "message": "not authorized", "alert_type": "alert-warning" }) user_list = get_all_users() for user in user_list: user_obj = load_user(user["_id"]) print("username " + user_obj.username) self.update_user_collections(user_obj) return jsonify({"success": True})
def get_resource_data_list(self, user_obj=None): user_list = get_all_users() result = [] larray = ["_id", "username", "full_name", "last_login", "email"] for user in user_list: urow = {} for field in larray: if field in user: urow[field] = str(user[field]) else: urow[field] = "" result.append(urow) return result
def users_route(user_id=None): if request.method == 'POST': first_name = utils.get_field(request, 'first_name', required=True) last_name = utils.get_field(request, 'last_name', required=True) email = utils.get_field(request, 'email', required=True) password = utils.get_field(request, 'password') fb_id = utils.get_field(request, 'fb_id') return users.new_user(first_name, last_name, email, password, fb_id) if user_id is None: return users.get_all_users() return users.get_user(user_id)
def do_GET(self): self._set_headers(200) response = {} # Parse URL and store entire tuple in a variable parsed = self.parse_url(self.path) if len(parsed) == 2: (resource, id) = parsed if resource == "categories": response = get_all_categories() if resource == "posts": if id is not None: response = get_single_post(id) pass else: response = get_all_posts() if resource == "users": if id is not None: pass else: response = get_all_users() if resource == "comments": if id is not None: pass else: response = get_all_comments() # Response from parse_url() is a tuple with 3 # items in it, which means the request was for # `/resource?parameter=value` elif len(parsed) == 3: (resource, key, value) = parsed if key == "user_id" and resource == "posts": response = get_posts_by_user(value) if key == "email" and resource == "users": response = get_user_by_email(value) self.wfile.write(response.encode())
def GET(self): query = web.ctx.query if query == "": user = users.get_user_by_sid() if user is None: return web.seeother('/login') else: return render.admin(users=users.get_all_users()) else: pattern = re.compile(r'method=(.+?)&username=(.+)') result = pattern.findall(query) method = result[0][0] username = result[0][1] if method == 'delete': users.del_user_by_name(username) response = {'message': 'delete'} logs.delete_user(username) return json.dumps(response)
def get_users(): responseJson = json.dumps(users.get_all_users()) print(responseJson) return Response(responseJson, mimetype='application/json')
"--encodings", required=True, help="path to serialized db of facial encodings") ap.add_argument("-d", "--detection-method", type=str, default="cnn", help="face detection model to use: either `hog` or `cnn`") args = vars(ap.parse_args()) # grab the paths to the input images in our dataset print("[INFO] quantifying faces...") imagePaths = list(paths.list_images(args["users"])) # initialize the list of known encodings and known names allUsers = users.get_all_users() knownEncodings = [] knownUsers = [] # knownNames = [] # loop over the image paths for (i, user) in enumerate(allUsers): print("[INFO] processing user {}/{}".format(i + 1, len(allUsers))) name = users.get_name_from_id(user) for imagePath in users.get_pictures_from_id(user): # load the input image and convert it from BGR (OpenCV ordering) # to dlib ordering (RGB) image = cv2.imread(imagePath) rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
def chat(): news_number = 1 Name = "" Age = 0 Birthday = "" while True: inp = Recognize.get_recognize_google() #inp = input("Input: ") if not inp: pass else: results = model.predict([bag_of_words(inp, words)])[0] results_index = numpy.argmax(results) tag = labels[results_index] if results[results_index] > 0.7: for tg in data["intents"]: if tg["tag"] == tag: responses = tg['responses'] if "song" == responses[0] and "songs" not in responses[0]: if "song" in inp.lower(): inp = inp.replace("song", "", 1) if " the " in inp.lower(): inp = inp.replace("the", "", 1) if "play" in inp.lower(): inp = inp.replace("play", "", 1) if "start" in inp.lower(): inp = inp.replace("start", "", 1) if "video" in inp.lower(): inp = inp.replace("video", "", 1) if "audio" in inp.lower(): inp = inp.replace("audio", "", 1) inp = inp.replace(" ", "") Voice.speak_flite("Playing Audio - " + inp) play_video(inp.lower()) elif "sleep" == responses[0]: call_dom() elif "convert" == responses[0]: us_string_place = 0 pkr_string_place = 0 for row in range(len(inp.split())): inp = inp.lower() inp = inp.lower() if inp.split()[row] == "us": us_string_place += row elif inp.split()[row] == "rupees": pkr_string_place += row res = [int(i) for i in inp.split() if i.isdigit()][0] if us_string_place > pkr_string_place: number = pkr_to_usd(res) Voice.speak_flite(str(number)) else: number = usd_to_pkr(res) Voice.speak_flite(str(number)) elif "spelling" == responses[0]: if "what" in inp: inp = inp.replace("what", "") if "is" in inp: inp = inp.replace("is", "") if "does" in inp: inp = inp.replace("does", "") if "of" in inp: inp = inp.replace("of", "") if "spelling" in inp: inp = inp.replace("spelling", "") if "spell" in inp: inp = inp.replace("spell", "") inp = inp.replace(" ", "") word = " ".join(inp) for row in range(len(word)): Voice.speak_flite(word[row]) elif "maths" == responses[0]: if 'square root' in inp: num = [int(i) for i in inp.split() if i.isdigit()][0] square_root = num**0.5 Voice.speak_flite(str(square_root)) else: first = [int(i) for i in inp.split() if i.isdigit()][0] second = [int(i) for i in inp.split() if i.isdigit()][1] if '+' in inp: Voice.speak_flite(str(first + second)) if '-' in inp: Voice.speak_flite(str(first - second)) if '/' in inp: Voice.speak_flite(str(first / second)) if '*' in inp: Voice.speak_flite(str(first * second)) elif "translate" == responses[0]: if "translate" in inp: inp = inp.replace("translate", "") if "to" in inp: inp = inp.replace("to", "") if "what" in inp: inp = inp.replace("what", "") if "does" in inp: inp = inp.replace("does", "") if "english" in inp.lower(): inp = inp.replace("english", "") inp = inp.replace(" ", "") Voice.speak_flite(translate_urdu_to_english(inp)) elif "urdu" in inp.lower(): inp = inp.replace("urdu", "") inp = inp.replace(" ", "") Voice.speak_flite(translate_english_to_urdu(inp)) elif "system" == responses[0]: if "shutdown" in inp or "poweroff" in inp: os.system("shutdown") elif "reboot" in inp: os.system("reboot") elif "time" == responses[0]: currentDT = datetime.datetime.now() if int(currentDT.strftime("%I")) <= 9: Voice.speak_flite( currentDT.strftime("%I:%M %p").replace('0', '', 1)) else: Voice.speak_flite(currentDT.strftime("%I:%M %p")) elif "day" == responses[0]: currentDT = datetime.datetime.now() Voice.speak_flite(currentDT.strftime("%A, %B, %Y")) elif "exit" == responses[0]: break elif "recipe" == responses[0]: if "recipe" in inp: inp = inp.replace("recipe", "") elif "for" in inp: inp = inp.replace("for", "") elif "of" in inp: inp = inp.replace("of", "") inp = inp.replace("give", "").replace("me", "").replace( " a ", "").replace("tell", "").replace("me", "").replace("about", "") info = get_recipe(inp) Voice.speak_flite(info[0]) Voice.speak_flite( "You will need the following ingredients") for row in info[1]: Voice.speak_flite(row) for row in info[2]: Voice.speak_flite(row) elif "weather" == responses[ 0] and "i can play songs, tell the weather, tell a joke" not in responses[ 0]: text = get_weather() Voice.speak_flite(text) elif "news" == responses[0]: if "next" in inp: news_number += 1 Voice.speak_flite(read_news_headlines(news_number)) else: Voice.speak_flite(read_news_headlines(news_number)) elif "joke" == responses[ 0] and not "i can play songs, tell the weather, tell a joke" == responses[ 0]: random_joke = joke() Voice.speak_flite(random_joke[0]) Voice.speak_flite(random_joke[1]) elif "update" == responses[0]: os.system("cd / && ./update.sh") sys.exit() elif "create" == responses[0]: Voice.speak_flite("Say The Users Name You Want to Create") name = Recognize.get_recognize_google() Voice.speak_flite("Say The Users Age") age = Recognize.get_recognize_google() Voice.speak_flite("Say The Users Birthday") birthday = Recognize.get_recognize_google() Voice.speak_flite("Name, " + name + " Age, " + age + " Birthday, " + birthday) Voice.speak_flite( "Are you sure you want to create this user") response = Recognize.get_recognize_google() if "yes" in response: Voice.speak_flite("Creating User") create_user(name, age, birthday) elif "user" == responses[0]: for row in get_all_users(): response_split = inp.split() for index in response_split: if row[0] == index: Name = row[0] Age = row[1] Birthday = row[2] if row[0] == "Zara": Voice.speak_flite( "Hello There Zarah, Welcome Back") elif row[0] == "Ayaan": Voice.speak_flite( "Hello There Aion, Welcome Back") else: Voice.speak_flite("Hello There " + row[0] + ", Welcome Back") elif "info" == responses[0]: if "birthday" in inp: if Birthday: Voice.speak_flite("Your Birthday comes on " + Birthday) else: Voice.speak_flite("Please say who you are") elif "age" in inp: if Age: Voice.speak_flite("Your Age is " + str(Age)) else: Voice.speak_flite("Please say who you are") elif "name" in inp: if Name: if Name == "Ayaan": Voice.speak_flite("Your Name is Aion") elif Name == "Zara": Voice.speak_flite("You Name is Zarah") else: Voice.speak_flite("Your Name is " + Name) else: Voice.speak_flite("Please say who you are") elif "search" == responses[0]: inp = inp.split() srch = [] for inp1 in inp: inp = inp1 if "is" in inp and "histroy" not in inp: pass elif "was" in inp: pass elif "are" in inp: pass elif "of" in inp: pass elif "who" in inp: pass elif "what" in inp: pass elif "how" in inp: pass elif "why" in inp: pass elif "does" in inp: pass elif "tell" in inp: pass elif "me" in inp: pass elif "about" in inp: pass elif "to" in inp and "histroy" not in inp: pass else: srch.append(inp) inp = srch Voice.speak_flite("Searching about " + " ".join(inp)) search = search_wikipedia(inp) Voice.speak_flite(search) else: Voice.speak_flite(random.choice(responses)) else: Voice.speak_flite("I do not Understand Please Retry")
DB_PATH = 'sqlite:///sochi_athletes.sqlite3' session = users.db_connect(DB_PATH) while True: choice = input('Выберете режим:\n' '1. Добавить пользователя\n' '2. Найти атлета с ближайшими к пользователю параметрами\n' '3. Показать всех пользователей\n' '4. Выйти\n>') if choice == '1': user = users.user_data_request() session.add(user) session.commit() print('\n', '=' * 21, sep='') print('Информация сохранена!') print('=' * 21, '\n') elif choice == '2': birhdate, height = users.get_user_from_db(session) if birhdate == 0 and height == 0: continue else: find_athlete.find_nearest_bdate(birhdate, session) find_athlete.find_nearest_height(height, session) elif choice == '3': users.get_all_users(session) elif choice == '4': break
response = Recognize.get_recognize_google() if "yes" in response: screen.fill((0, 0, 0)) screen.blit(time, [0, 0]) screen.blit(monthday, [0, 50]) blit_text(screen, "Creating User", (0, 275), fontbig, color=pygame.Color("white")) pygame.display.flip() pygame.display.update() Voice.speak_flite("Creating User") create_user(name, age, birthday) elif "I am" in response: for row in get_all_users(): response_split = response.split() for index in response_split: if row[0] == index: Name = row[0] Age = row[1] Birthday = row[2] if row[0] == "Zara": screen.fill((0, 0, 0)) screen.blit(time, [0, 0]) screen.blit(monthday, [0, 50]) blit_text(screen, "Hello There Zara, Welcome Back", (0, 275), fontbig,
def get_all_users(): time.sleep(3) return jsonify(users.get_all_users())
def do_GET(self): self._set_headers(200) response = {} parsed = self.parse_url(self.path) if len(parsed) == 2: ( resource, id ) = parsed if resource == "users": if id is not None: response = get_user_by_id(id) else: response = get_all_users() if resource == "categories": if id is not None: pass else: response = get_all_categories() elif resource == "tags": if id is not None: pass else: response = get_all_tags() elif resource == "posts": if id is not None: response = get_post_by_id(id) else: response = get_all_posts() elif resource == "comments": if id is not None: pass else: response = get_all_comments() elif resource == "subscriptions": if id is not None: response = get_subscribed_posts_by_id(id) else: pass elif resource == "reactions": if id is not None: pass else: response = get_all_reactions() elif resource == "postreactions": if id is not None: response = get_postreactions_by_id(id) else: pass # Response from parse_url() is a tuple with 3 # items in it, which means the request was for # `/resource?parameter=value` elif len(parsed) == 3: ( resource, key, value ) = parsed if key == "user_id" and resource == "posts": response = get_posts_by_user_id(value) elif key.lower() == "isadmin" and resource == "users": response = get_users_by_profile_type(value) elif key == "category_id" and resource == "posts": response = get_posts_by_category_id(value) elif key == "tag_id" and resource == "posts": response = get_posts_by_tag_id(value) elif key == "q" and resource == "posts": response = get_posts_by_title_search(value) self.wfile.write(response.encode())