def upload454666888(): # 下面这一段是通用的. result = Auth.identify(Auth, request) print(898989898989, result) if not result["status"]: return jsonify({"status": 401}) if result["status"]: username2id = result['data'] # 因为是类函数所以第一个参数传入这个类他自己. user = Users.get(Users, result['data']) print(66666, user.username) wenjianjia = user.username username2id = result['data'] # 因为是类函数所以第一个参数传入这个类他自己. user = Users.get(Users, result['data']) # result['data'] 表示的是用户id号. print(66666, user.username) print(66666, user.param1) # 把所有需要保存的文件名放入param1里面 print(type(user.param1)) import json a = json.loads((user.param1)) # 通过loads读取json字符串 print(888888, a) fanhui = {} print("zonggiongshi j", a) for i in a: iii = r"uploads/" + user.username + r'/' + i + ".json" print(iii) with open(iii, encoding='utf-8') as i2: import json tmp = json.load(i2) fanhui[i] = tmp print(i) print(len(fanhui)) print(fanhui.keys()) print(fanhui['古文观止2']) # # wenjianjia = user.username # # # data = request.get_json() # print(data) # print(data['filename']) # print(data['data']) # import json # with open(r"uploads/"+wenjianjia+r'//'+data['filename']+".json", 'w', encoding='utf-8') as f: # json.dump(data['data'], f, ensure_ascii=False) return jsonify(fanhui)
def upload454666(): # 下面这一段是通用的. result = Auth.identify(Auth, request) print(898989898989, result) if not result["status"]: return jsonify({"status": 401}) if result["status"]: username2id = result['data'] # 因为是类函数所以第一个参数传入这个类他自己. user = Users.get(Users, result['data']) print(66666, user.username) wenjianjia = user.username # # wenjianjia = user.username # # # data = request.get_json() # print(data) # print(data['filename']) # print(data['data']) # import json # with open(r"uploads/"+wenjianjia+r'//'+data['filename']+".json", 'w', encoding='utf-8') as f: # json.dump(data['data'], f, ensure_ascii=False) return r'环境保存到服务器额数据库了'
def google_login(): from app import Users, db state = None while state is None: google_session = OAuth2Session(CLIENT_ID, CLIENT_SECRET, scope=AUTHORIZATION_SCOPE, redirect_uri=AUTH_REDIRECT_URI) uri, state = google_session.create_authorization_url(AUTHORIZATION_URL) flask.session[AUTH_STATE_KEY] = state print(f"\n\nGoogle Auth State: \n\n{state}\n\n") # flask.session.permanent = True try: user_info = get_user_info() email = user_info['email'] user = Users.query.filter_by(email=email).first() print(f"\n\n\n{user}\n\n\n") if user is None: user = Users(email=user_info['email'], name=user_info['name'], avatar=user_info['picture']) db.session.add(user) db.session.commit() except: return flask.redirect(uri, code=302) return flask.redirect(uri, code=200)
def mocked_user_model(mocked_uuid): mocked_uuid = mocked_uuid() return Users( "*****@*****.**", str(mocked_uuid), "A Name", AuthType.GOOGLE, "link", )
def test_1_create_user(self): db.session.add( Users(last_name='Test', first_name='Test1', patronymic_name='Test2', password='******', email='*****@*****.**')) db.session.commit() user = Users.query.filter_by(email='*****@*****.**').first() self.assertEqual('*****@*****.**', user.email)
def add_user_submit(n_clicks, UserID, UserPassword, UserType, UserFN, UserLN): print('Got here') if n_clicks > 0: ed_user = Users(UserID=UserID, UserPassword=UserPassword, UserFirstName=UserFN, UserLastName=UserLN, UserType=UserType) db.session.add(ed_user) ed_portfolio = Portfolio(UserID=UserID, Cash=1000000) db.session.add(ed_portfolio) db.session.commit() return 2
def add_admin(): admin_user = { 'name': 'admin', 'email': '*****@*****.**', 'password': '******' } admin = Users(name=admin_user['name'], email=admin_user['email'], password=admin_user['password']) try: db.session.add(admin) db.session.commit() except SQLAlchemyError as e: error = str(e.__dict__['orig']) return error
def createAccount(): from app import db, Users db.create_all() if request.method == 'POST': username = request.form['username'] password = request.form['password'] confirm_password = request.form['password2'] name = request.form['name'] if password != confirm_password: render_template('password_error.html') redirect('/') else: db.session.add( Users(username=username, password=password, name=name)) db.session.commit() return render_template("createAccount.html")
def upload222222223(): # 下面这一段是通用的. result = Auth.identify(Auth, request) print(898989898989, result) if not result["status"]: return jsonify({"status": 401}) if result["status"]: username2id = result['data'] beidelete = request.args['delete'] # 获取参数的方法 # 因为是类函数所以第一个参数传入这个类他自己. user = Users.get(Users, result['data']) print(66666, user.username) wenjianjia = user.username if not os.path.exists(r"uploads/" + wenjianjia): return jsonify([]) os.remove(r"uploads/" + wenjianjia + '/' + str(beidelete)) tmp = os.listdir(r"uploads/" + wenjianjia) tmp2 = [] for i in tmp: tmp2.append(i.split('.')[-2]) print(tmp2) # name2=request.args['file'] # 获取参数的方法 # print(111111111111111111111111,name2) # 为什么目录跳了一级??? # return send_file(r"..\uploads\fuck222.png") # return send_file(r"..\uploads\1.txt") # attachment_filename the filename for the attachment if it differs from the file’s filename. # # 可以了,上传下载都可以了 # with open(r"uploads/"+wenjianjia+r'/'+name2+".json",encoding='utf-8') as f: # # tmp=json.load(f) # print(tmp) # print(type(tmp),343434343) # tmp2={'data':tmp} # # tmp2=jsonify(tmp2) # print(9999999999) # print(tmp2['data'][0]) return jsonify(tmp2)
def upload4422(): # 下面这一段是通用的. result = Auth.identify(Auth, request) print(898989898989, result) if not result["status"]: return jsonify({"status": 401}) if result["status"]: username2id = result['data'] # 因为是类函数所以第一个参数传入这个类他自己. user = Users.get(Users, result['data']) print(66666, user.username) wenjianjia = user.username + "_juzifenxi" # 这里规定带有这个后缀的是句子,不带的是篇章 f = request.files #http://www.voidcn.com/article/p-hfxcccsv-btt.html print(7777777777777, f) print(7777777777777, f.values()) k = f.getlist('file') changdu = len(k) print(k) num = 0 for i in k: print(i) print(type(i)) # 先获取文件的名字. print(1111111111111, i.filename) name2 = i.filename.split('.')[-2] + '.json' basepath = os.path.dirname(__file__) # 当前文件所在路径 upload_path = os.path.join(basepath, '/uploads') #注意:没有的文件夹一定要先创建,不然会提示没有该路径 if not os.path.exists(r"uploads/" + wenjianjia): os.mkdir(r"uploads/" + wenjianjia) pa34 = r"uploads/" + wenjianjia + r"/" + name2 # i.save(pa34) # 带字符串的一定要前面写上r.这样少了很多转义字符,方便多了!!!!!!!!!!!!!11 pageToSentences(i, pa34) # 这里面有保存代码 print("句子解析的结果!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") print("保存在", pa34) print(name2) return "成功完成" + str(changdu) + "个文件的句子对齐任务" return "bug"
def user(): if request.method == 'GET': query = request.args print(query) data = Users.query.filter_by(email=query["email"]).first() return str(data) data = request.args if request.method == 'POST': user = Users(email=data['email'], password=data['password']) db.session.add(user) db.session.commit() return 'User has been added' if request.method == 'PATCH': pass if request.method == 'DELETE': pass
def upload454(): # 下面这一段是通用的. result = Auth.identify(Auth, request) print(898989898989, result) if not result["status"]: return jsonify({"status": 401}) if result["status"]: username2id = result['data'] # 因为是类函数所以第一个参数传入这个类他自己. user = Users.get(Users, result['data']) print(66666, user.username) wenjianjia = user.username data = request.get_json() print(data) print(data['filename']) print(data['data']) print(data['page']) import json # print(json.load(r"uploads/"+wenjianjia+r'/'+data['filename']+".json",ensure_ascii=False)) print(99999999999999999999999999999) with open(r"uploads/" + wenjianjia + r'/' + data['filename'] + ".json", 'r', encoding='utf-8') as f: # print(f) tmp = json.load(f) # print(8888888888,tmp) # json.dump(data['data'], f, ensure_ascii=False) print(999999999333333333333333) tmp[data['page'] - 1] = data['data'] # print(tmp[data['page']]) with open(r"uploads/" + wenjianjia + r'/' + data['filename'] + ".json", 'w', encoding='utf-8') as f: json.dump(tmp, f, ensure_ascii=False) return r'json保存到服务器了'
def Sign(): form = RegisterForm() if form.validate_on_submit(): hashed_password = generate_password_hash(form.password.data, method='sha256') users = Users.query.filter_by(username=form.username.data).first() usersEmail = Users.query.filter_by(email=form.email.data).first() if users is None or usersEmail is None: new_user = Users(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(new_user) db.session.commit() login_user(new_user, remember=form.remember.data) flash('Vous êtes bien connecté en tant que ' + form.username.data) return redirect(url_for('main.home')) else: flash('Identifiant ou Email déjà utilisé') return render_template('sign.html', form=form)
def upload2(): # 下面这一段是通用的. result = Auth.identify(Auth, request) print(898989898989, result) if not result["status"]: return jsonify({"status": 401}) if result["status"]: username2id = result['data'] # 因为是类函数所以第一个参数传入这个类他自己. user = Users.get(Users, result['data']) print(66666, user.username) wenjianjia = user.username name2 = request.args['file'] # 获取参数的方法 print(111111111111111111111111, name2) # 为什么目录跳了一级??? # return send_file(r"..\uploads\fuck222.png") # return send_file(r"..\uploads\1.txt") # attachment_filename the filename for the attachment if it differs from the file’s filename. # 可以了,上传下载都可以了 path = r"../uploads/" + wenjianjia + "/" + name2 + ".json" path2 = os.path.abspath(path) print(path2) # return jsonify(path2) tmp = send_from_directory(r"../uploads/" + wenjianjia, filename=name2 + ".json", as_attachment=True) print(tmp) print(type(tmp)) print(tmp.headers) # 下面这段是修改header的方法.!!!!!!!!!!!!!!!!!!!!!! #<class 'werkzeug.datastructures.Headers'> 看源码 print(type(tmp.headers)) print("45645645", tmp.headers) tmp.headers.add('Content-Type', 'application/octet-stream') # tmp.add_header('Authorization', 'Bearer {xxxxxxx}') # tmp.header['content-type']='application/octet-stream' return tmp
def upload2223(): # 下面这一段是通用的. result = Auth.identify(Auth, request) print(898989898989, result) if not result["status"]: return jsonify({"status": 401}) if result["status"]: username2id = result['data'] # 因为是类函数所以第一个参数传入这个类他自己. user = Users.get(Users, result['data']) print(66666, user.username) wenjianjia = user.username + "_juzifenxi" # 这里规定带有这个后缀的是句子,不带的是篇章 name2 = request.args['file'] # 获取参数的方法 print(111111111111111111111111, name2) # 为什么目录跳了一级??? # return send_file(r"..\uploads\fuck222.png") # return send_file(r"..\uploads\1.txt") # attachment_filename the filename for the attachment if it differs from the file’s filename. tmp = send_from_directory(r"../uploads/" + wenjianjia, filename=name2 + ".json", as_attachment=True) print(tmp) print(type(tmp)) print(tmp.headers) # 下面这段是修改header的方法.!!!!!!!!!!!!!!!!!!!!!! #<class 'werkzeug.datastructures.Headers'> 看源码 print(type(tmp.headers)) print("45645645", tmp.headers) tmp.headers.add('Content-Type', 'application/octet-stream') return tmp # 可以了,上传下载都可以了 return send_from_directory(r"../uploads/" + wenjianjia, filename=name2 + ".json", as_attachment=True)
def upload2222(): # 下面这一段是通用的. result = Auth.identify(Auth, request) print(898989898989, result) if not result["status"]: return jsonify({"status": 401}) if result["status"]: username2id = result['data'] # 因为是类函数所以第一个参数传入这个类他自己. user = Users.get(Users, result['data']) print(66666, user.username) wenjianjia = user.username name2 = request.args['file'] # 获取参数的方法 page2 = request.args['page'] # 获取参数的方法 page2 = int(page2) print(111111111111111111111111, name2) # 为什么目录跳了一级??? # return send_file(r"..\uploads\fuck222.png") # return send_file(r"..\uploads\1.txt") # attachment_filename the filename for the attachment if it differs from the file’s filename. # 可以了,上传下载都可以了 with open(r"uploads/" + wenjianjia + r'/' + name2 + ".json", encoding='utf-8') as f: tmp = json.load(f) # print("111111111111111111111111",tmp) # print(22222222222222,page2) # print(tmp[page2-1]) tmp3 = tmp[page2 - 1] # print(tmp) # print(type(tmp),343434343) # tmp2={'data':tmp} # # tmp2=jsonify(tmp2) # print(9999999999) # print(tmp2['data'][0]) print(type(tmp3)) tmp3['totalpage'] = len(tmp) return jsonify(tmp3)
from app import db, Users db.drop_all() db.create_all() testuser = Users(first_name='Grooty', last_name='Toot') db.session.add(testuser) db.session.commit() ## works!
address_state=fake.state(), address_country='US', address_zip=fake.zipcode(), phone=fake.phone_number(), email=fake.free_email()) # set created date to simulate users creating accounts throughout the year created_date = fake.date_this_year(before_today=True, after_today=False) # create a record from sqlalchemy model user_record = Users(id=user.id, company=user.company, date_created=created_date, description=user.description, email=user.email, name=user.name, phone=user.phone, address_city=user.address_city, address_country=user.address_country, address_line1=user.address_line1, address_line2=user.address_line2, address_state=user.address_state, address_zip=user.address_zip, anniversary=str(created_date.month) + '-' + str(created_date.day), password=fake.md5()) # add model to db session db.session.add(user_record) # add all records to db session db.session.commit()
from app import db, Users db.drop_all() db.create_all() testuser = Users( first_name='kazi', last_name='uddin' ) # Extra: this section populates the table with an example entry db.session.add(testuser) db.session.commit()
from app import db, Users db.drop_all() db.create_all() testuser = Users( first_name='Grooty', last_name='Toot' ) # Extra: this section populates the table with an example entry db.session.add(testuser) db.session.commit()
from app import db, Users db.drop_all() db.create_all() user_1 = Users(first_name='Jalal', last_name="Saadat") db.session.add(user_1) db.session.commit()
def addUser(username,email): user = Users(username=username,email=email) db.session.add(user) db.session.commit()
from app import db_add_user, db_add_comment from app import add_event_id, mock_on_likes_dislikes KEY_INPUT = 'input' KEY_EXPECTED = 'expected' INPUT = "id, event_id" EXPECTED_OUTPUT = "expected" ID = 'id' EVENT_ID = 'eventID' FIRST_ADDITION = Bookmarks(clientId='234', event_id='567') SECOND_ADDITION = Bookmarks(clientId='678', event_id='907') THIRD_ADDITION = Bookmarks(clientId='1234', event_id='5678') INITIAL_PERSON = Bookmarks(clientId='1234', event_id='1234') initial_user = Users(id="1234567", email="*****@*****.**", firstName="NameFirst", familyName="NameLast", imageURL="url.img.jpg") expected_user = Users(id="7654321", email="*****@*****.**",firstName="firstname",familyName="lastname",imageURL="https://lh3.googleusercontent.com/754321") class AddUserTestCase(unittest.TestCase): def setUp(self): self.success_test_params = [ { KEY_INPUT: { "googleId": "7654321", "email": "*****@*****.**", "givenName": "firstname", "familyName": "lastname", "imageUrl": "https://lh3.googleusercontent.com/754321", }, KEY_EXPECTED: [initial_user, expected_user], }, ]
from app import db, Users db.drop_all() ##deletes db db.create_all() ## creates db user_1 = Users(first_name="Arman", Last_name="Khan") db.session.add(user_1) db.session.commit()