def profile_get_pic(user): from urllib.parse import unquote adding = request.args.get("adding") url = unquote(request.args.get("url")) cat = request.args.get("cat") title = unquote(request.args.get("title")) if adding == "true": favorites = users_controller.read_favorites_json(user) favorites[cat].append(title) users_controller.write_favorites_json(favorites, user) title = title.replace(":", "").replace("(", "").replace(")", "").replace(" ", "").replace("&","").replace("'", "").replace("\"", "").replace(".", "") extension = "jpg" if ".png" in url: extension = "png" os.system(f"curl -sk \"{url}\" -o static/pics/{cat}/{title}.jpg") im = Image.open(f"static/pics/{cat}/{title}.jpg") if cat in ["beer", "books"]: ratio = float(500 / im.size[1]) im = im.resize((int(ratio*im.size[0]), 500)) else: ratio = float(500 / im.size[0]) im = im.resize((500,int(ratio*im.size[1]))) im = im.convert("RGB") im.save(f"static/pics/{cat}/{title}.jpg") return jsonify({"success": 1})
def profile_edit_cat_item(user): cat = request.args.get("cat") idx = int(request.args.get("idx")) remove = request.args.get("remove") # need tier favorites = users_controller.read_favorites_json(user) if remove: del favorites[cat][idx] users_controller.write_favorites_json(favorites, user) return jsonify({"success": 1})
def profile_reassign_ranks(user): cat = request.args.get("cat") fromId = int(request.args.get("fromId")) toId = int(request.args.get("toId")) isNew = request.args.get("isNew") newVal = request.args.get("newVal") favorites = users_controller.read_favorites_json(user) fromVal = favorites[cat][fromId] del favorites[cat][fromId] if fromId < toId: favorites[cat].insert(toId - 1, fromVal) else: favorites[cat].insert(toId, fromVal) users_controller.write_favorites_json(favorites, user) return jsonify({"success": 1})
def profile_add_cat(user): new_cat = request.args.get("cat").replace(" ", "_").lower() favorites = users_controller.read_favorites_json(user) favorites[new_cat] = [] users_controller.write_favorites_json(favorites, user) return jsonify({"success": 1})
def profile_route(user): favorites = users_controller.read_favorites_json(user) category_header_html = get_category_html(user, favorites) category_html = get_home_page_html(user, favorites) autocomplete_arr = get_autocomplete_arr(favorites) return render_template("profile.html",user=user, category_html=category_html, category_header_html=category_header_html, profile_data=format_data(favorites), autocomplete_arr=autocomplete_arr, condense=True)