def summary(): print("Starting scrap") URLS = sheet_instance.col_values(3)[1:] URLS = [i for i in URLS if i] for i in URLS: try: data = GetCountAndResourcesDone(i) except: data = { "quests":[], "dp":'', "name":'' } user = UserModel.objects.filter(qwiklabs_id=i) if user.exists(): user = user[0] user.quests_status = len(data['quests']) user.quests = data['quests'] user.name = data['name'] user.dp = data['dp'] else: user = UserModel() user.qwiklabs_id = i user.quests_status = len(data['quests']) user.quests = data['quests'] user.name = data['name'] user.dp = data['dp'] user.save() print(i)
def delete(self): """ Delete user """ user_data = request.get_json() user = UserModel.find_by_username(user_data["user_name"]) if user is None: user = UserModel.find_by_email(user_data["email"]) if user is None: return {"message": gettext("error_user_not_found")}, 404 try: user.delete() except Exception: return {"message": gettext("error_user_deleting")}, 500 return {"message": gettext("user_deleted")}, 200
def post(self): user_data = request.get_json() print(user_data) user = UserModel.find_by_username(user_data["user_name"]) if user and safe_str_cmp(user.password, user_data["password"]): access_token = create_access_token(user.user_name, fresh=True) refresh_token = create_refresh_token(user.user_name) return ( { "access_token": access_token, "refresh_token": refresh_token }, 200, ) return {"message": gettext("error_user_invalid_credentials")}, 401
def post(self): """ Create new user """ user_data = request.get_json() if UserModel.find_by_username(user_data["user_name"]): return {"message": gettext("error_user_exists")}, 400 if UserModel.find_by_email(user_data["email"]): return {"message": gettext("error_user_exists")}, 400 user = UserModel(**user_data) try: user.save() except Exception: return {"message": gettext("error_user_creating")}, 500 return Response(user.to_json(), mimetype="application/json", status=200)