def parse_user(self, user_string: str): user_elements = user_string.replace("\n", "").split('::') return User(user_id=int(user_elements[0]), gender=Gender(user_elements[1]), age=Age(int(user_elements[2])), occupation=Occupation(int(user_elements[3])), zipcode=Zipcode(user_elements[4]))
def __init__(self, **kwargs): if kwargs: from core.user import User self.user = User(**kwargs) self.base_data = dict(all_fuc=self.frame.allow_fuc, all_column=self.frame.allow_column) pass
def new_test(self): self.add_new = AddTestDialog() self.main_window.setDisabled(True) self.add_new.show() if self.add_new.exec_(): self.user = User(self.add_new.name, self.add_new.age, self.add_new.gender) self.main_window.setDisabled(False) self.main_window.testing.setDisabled(False) self.main_window.testing.answer.setDisabled(True) self.main_window.testing.test_info.name.setText(" " + self.user.name) self.main_window.testing.test_info.age.setText(" " + str(self.user.age)) self.main_window.testing.test_info.gender.setText( " " + str(self.user.gender.value)) self.main_window.testing.test_info.procedure.setText( " " + str(self.add_new.procedure.value)) if self.add_new.procedure == ProcedureType.BASIC: self.main_window.testing.test_info.iterations.setText( " " + str(self.add_new.iterations)) self.main_window.testing.test_info.grid.setText(" 5x5") self.main_window.testing.test_info.resH.setText( " 45 degrees (H)") self.main_window.testing.test_info.resV.setText( " 45 degrees (V)") self.b0.setDisabled(True) self.b1.setDisabled(False)
def user_test(wholeTree=True): patrik = User() patrik.login("patrikch", "123456") print(patrik.is_logged) print(str(patrik)) tree = patrik.project_tree printTree(tree)
def __init__(self, login, password, like_per_day=1000, media_max_like=10, media_min_like=0, follow_per_day=0, follow_time=5 * 60 * 60, unfollow_per_day=0, comments_per_day=0, tag_list=['cat', 'car', 'dog'], max_like_for_one_tag=5, log_mod=0): super(InstaBot, self).__init__() self.time_in_day = 24 * 60 * 60 # Like self.like_per_day = like_per_day if self.like_per_day != 0: self.like_delay = self.time_in_day / self.like_per_day # Follow self.follow_time = follow_time self.follow_per_day = follow_per_day if self.follow_per_day != 0: self.follow_delay = self.time_in_day / self.follow_per_day # Unfollow self.unfollow_per_day = unfollow_per_day if self.unfollow_per_day != 0: self.unfollow_delay = self.time_in_day / self.unfollow_per_day # Comment self.comments_per_day = comments_per_day if self.comments_per_day != 0: self.comments_delay = self.time_in_day / self.comments_per_day # Don't like if media have more than n likes. self.media_max_like = media_max_like # Don't like if media have less than n likes. self.media_min_like = media_min_like # Auto mod seting: # Default list of tag. self.tag_list = tag_list # Get random tag, from tag_list, and like (1 to n) times. self.max_like_for_one_tag = max_like_for_one_tag self.media_by_tag = [] log_string = 'Insta Bot v1.1 start at %s:' % \ (datetime.datetime.now().strftime("%d.%m.%Y %H:%M")) logger.info(log_string) session = requests.Session() # create a new user and log the user into the session self.user = User(session, login, password) self.user.login() self.API = API(self.user) signal.signal(signal.SIGTERM, self.cleanup) atexit.register(self.cleanup)
def register(msg): print(msg) #username password #创建一个属于这个用户的家目录,把用户名的密码写在userinfo #记录用户的初试磁盘配额,记录文件大小,记录用户当前所在的目录 user_obj = User(msg['name']) #记录用户的信息 os.mkdir(user_obj.home) #创建一个家目录
def signup(): if current_user.is_authenticated: return redirect(url_for('web.index')) form_data = {} if request.method == 'POST': validation_result = validate_registration_form(request.form.to_dict()) if ValidationResults.SUCCESS in validation_result: try: user = User(request.form) token = s.dumps(user.email, salt=current_app.config.get('MAIL_SALT')) msg = generate_confirmation_mail(user.email, token) mail.send(msg) add_new_user(user) session['email_to_confirm'] = user.email return redirect(url_for('web.finish_signup')) except Exception as ex: flash(str(ex)) for message in validation_result: flash(message.value) form_data = request.form return render_template( 'signup.html', google_client_key=current_app.config.get('GOOGLE_CLIENT_KEY'), form_data=form_data)
def create_user(username, password, admin=False, permissions=DEFAULT_PERMISSIONS): permissions["admin"] = admin u = User(username=username, permissions=permissions) u = set_password(u, password) return u.save()
def create_user(self, name, password, phone, role='USER'): print(role) self.session.add( User(user_name=name, true_name=name, telephone=phone, password_md=password, role=role))
def create_user(username): user = User(username=username, permissions=DEFAULT_PERMISSIONS) user.api_key = User.generate_api_key() user.password = urandom(24).encode('hex') user.session_token = generate_session_token(user) user.enabled = True user.save() return user
def register(msg): user_obj = User(msg['username']) pickle_path = os.path.join(settings.pickle_path, msg['username']) with open(pickle_path, 'wb') as f: pickle.dump(user_obj, f) os.mkdir(user_obj.home) with open(settings.user_info, 'a') as f: f.write('%s|%s|%s\n' % (msg['username'], msg['password'], pickle_path)) return True, pickle_path
def commen_user_menu(user_data, user): """ :param user_data:<list> 包含所有用户账号的列表 :param user:<core.user.User object> 用户实例 :return:None 这个函数用来和普通用户交互,并分发功能。或者让管理员也可以使用这个系统 """ # 初始化一个交易中心实例 tc = TradingCenter(user) print("当前余额为%s" % user.balances) while True: print(""" 请输入序号选择功能 1. 购物 2. 转账 3. 提现 4. 还款 5. 查询流水 6. 退出 """) choice = input(">>>").strip() if choice == "1": # 用户输入的值为1时,初始化一个购物车实例,调用购物方法 shopping = ShoppingCar(user.balances, tc) shopping.display_menu() elif choice == "2": # 用户输入的值为2时,判断用户是否存在,如果存在,调用交易中心的转账方法 outer_user = input("请输入转入账户的账户名:") if outer_user in user_data: money = input_int("请输入转账金额:") tc.transfer(User(outer_user), money) else: # 不存在则提示用户 print("账户不存在,请重新输入!") elif choice == "3": # 如果用户的输入值为3 ,调用交易中心的提现方法 money = input_int("请输入提现金额:") tc.cash_out(money) elif choice == "4": # 如果用户的输入值为4,调用交易中心的还款方法 money = input_int("还款金额") tc.reimbursement(money) elif choice == "5": # 调用交易中心的显示日志的方法 tc.display_user() elif choice == "6": # 用户选择退出时,退出程序 access_log.info("用户%s退出程序" % user.account) # 这里休眠0.1秒是为了 输出的日志消息 不会影响用户的输入 sleep(0.1) exit() else: # 用户输入错误时提示用户 print("输入的选项有误,请重新输入!")
def _auth(self, *args): """注册函数""" data_header = args[0] username = data_header["username"] password = data_header["password"] obj = User() status = obj.enroll(username, password) if status == 651: obj.create_directory() # 创建用户家目录 self.send_msg(status)
def _auth(self, conn, data_header): """注册功能""" username = data_header["username"] password = data_header["password"] user_obj = User() ret = user_obj.enroll(username, password, action_logger) if ret == 651: user_obj.create_directory() user_obj.save() self.send_msg(conn, ret)
def user_regester(username, password, phone=''): from core import CMS setting = CMS.setting_info('system') if 'regester_admin' in setting.keys(): setting = setting['regester_admin'] from core.user import User login = CMS( User(ident=setting['username'], pwd=setting['password'])) is_regester = login.UserMod().create(username, password, phone) if not is_regester['success']: raise Exception('Unknow error cant create user') return {'success': True} else: raise Exception('setup regester fuc first!')
def register(msg): # username, password # 创建一个属于这个用户的家目录 # 把用户名密码写进userinfo文件里,记录用户名 # 记录用户的初始磁盘配额,并记录下来 # 记录文件大小 # 记录用户当前所在的目录 user_obj = User(msg['username']) # 记录用户的信息在内存里 pickle_path = os.path.join(settings.pickle_path, msg['username']) with open(pickle_path, 'wb') as f: pickle.dump(user_obj, f) os.mkdir(user_obj.home) # 创建一个属于这个用户的对象 with open(settings.user_info, 'a') as f: f.write('%s|%s|%s' % (msg['username'], msg['pwd'], pickle_path)) return True
def register(msg): # 创建一个属于这个用的家目录,并记录下来 # 记录用户的初始磁盘配额 # 记录文件大小 # 记录用户当前所在的目录 user_obj = User(msg['name']) pickle_path = os.path.join(settings.pickle_path, msg['username']) with open(pickle_path, 'wb') as f: pickle.dump(user_obj, f) os.mkdir(user_obj.home) # 把用户名密码写进userinfo文件里,并记录用户名 with open(settings.user_info, 'a') as f: f.write('{}|{}|{}'.format(msg['username'], msg['password'], pickle_path)) return True
def register(msg): """登录认证 1.创建一个该用户的家目录,并记录下来 2.把用户名和密码写进userinfo文件里,记录用户名 3.记录用户的的磁盘配额 4.记录文件大小 5.记录用户当前所在的目录 """ user_obj = User(msg['username']) # 记录用户的信息在内存里 # 传入name参数 pickle_path = os.path.join(settings.pickle_path, msg['username']) with open(pickle_path, 'wb') as f: pickle.dump(user_obj, f) os.mkdir(user_obj.home) # 创建属于这个用户的家目录 在home文件夹下 with open(settings.user_info, 'a') as f: f.write('%s|%s|%s' % (msg['username'], msg['password'], pickle_path)) return True
def register(msg): user_obj = User(msg['username']) #记录用户的信息在内存里 with open(setting.userinfo, 'r') as f: for line in f: name, password, path = line.split('|') if name == msg['username']: return '用户名已存在' pickle_path = os.path.join(setting.pickle_path, msg['username']) with open(pickle_path, 'wb') as f: pickle.dump(user_obj, f) os.mkdir(user_obj.home) #创建属于这个用户的家目录 md5 = md5_password(msg['password']) #加密密码 with open(setting.userinfo, 'a') as f: f.write('%s|%s|%s\n' % (msg['username'], md5, pickle_path)) return '注册成功'
def register(msg): print(msg) # username password # 创建一个属于这个用户的家目录,并记录下来 # 把用户名密码 写进userinfo文件里,记录用户名 # 记录用户的初始磁盘配额 # 记录用户当前所在的目录 user_obj = User(msg) # 将用户信息写入文件,再将文件路径写到userinfo中 pickle_path = os.path.join(settings.pickle_path, msg['username']) with open(pickle_path, 'wb') as f: pickle.dump(user_obj, f) with open(settings.user_info, 'a') as f: f.write('%s|%s|%s' % (msg['username'], msg['password'], pickle_path)) os.mkdir(user_obj.home) # 创建家目录 return True
async def process_message(self, ws, text): try: data = json.loads(text) except: return log.warning('Unexpected stuff was thrown from mother base :p') if data['command'] == 'statistics': response = {'type': 'statistics', 'data': g.c_globals.stats.get_stats_assoc()} log.debug('MotherBase requested stats: %s' % str(response)) await ws.send_json(response) elif data['command'] == 'pixels' and 'data' in data: log.info('Received %s tasks from mother base.' % len(data['data'])) g.c_globals.task_handler.extend(data['data']) log.info('%s total tasks to proceed' % len(g.c_globals.task_handler)) elif data['command'] == 'add_users' and 'data' in data: log.info("Received %s users from mother base." % len(data['data'])) for user in data['data']: g.c_globals.user_handler.append(User(user['vk_websocket'], user['vk_id']))
def test_user_project_tree(self): """User folder-project tree should be different""" patrik = User() patrik.login("patrikch", "123456") tree = patrik.project_tree self.assertEqual(1, len(tree)) self.assertEqual("root", tree[0].name) self.assertEqual(4, len(tree[0].children)) self.assertEqual("d", tree[0].children[0].type) self.assertEqual("d", tree[0].children[1].type) self.assertEqual("d", tree[0].children[2].type) self.assertEqual("p", tree[0].children[3].type) self.assertEqual(6, len(tree[0].children[0].children)) self.assertEqual("d", tree[0].children[0].children[0].type) self.assertEqual("d", tree[0].children[0].children[1].type) self.assertEqual("p", tree[0].children[0].children[2].type) self.assertEqual("p", tree[0].children[0].children[3].type) self.assertEqual("p", tree[0].children[0].children[4].type) self.assertEqual("p", tree[0].children[0].children[5].type)
def post(self): if current_user.is_authenticated: return abort(HTTPStatus.METHOD_NOT_ALLOWED, message='You must logout first') validation_result = RegistrarionData.validate(api.payload) if ValidationResults.SUCCESS in validation_result: try: user = User(api.payload) token = s.dumps(user.email, salt=current_app.config.get('MAIL_SALT')) msg = generate_confirmation_mail(user.email, token) mail.send(msg) add_new_user(user) return jsonify( message='Registration successful. Verification mail sent.') except SMTPRecipientsRefused as ex: abort(HTTPStatus.BAD_REQUEST, message='Incorrect e-mail') except Exception as ex: abort(HTTPStatus.INTERNAL_SERVER_ERROR, message=repr(ex)) error_list = [res.value for res in validation_result] return abort(HTTPStatus.BAD_REQUEST, message=str(error_list))
# coding=utf-8 from core import CMS from core.user import User from backstage.model import CMSModel super = CMS(User(ident='super', pwd='superadmin')) # user = CMS(User(ident='lalala', pwd='nashishenmegui')) data = { "content": "这是一段普通的测试内容啊啊啊啊啊啊啊啊", "title": "测试文章", "author_name": "作者名字", "author_id": "57ce5af90b0555043c60e7d9", "from": "文章来源火星", "thumbnail": "http://ajcreative.net/wp-content/uploads/2014/12/blog-head.jpg", "images": [{ "img_src": "https://www.baidu.com/img/baidu_jgylogo3.gif", "description": "这是百度logo", "url_to": "https://www.baidu.com/" }, { "img_src": "https://www.baidu.com/img/baidu_jgylogo3.gif", "description": "这是百度logo", "url_to": "https://www.baidu.com/" }] }
#!/usr/bin/python # -*- coding: UTF-8 -*- """ @description @author wangsl [email protected] @version v1.0.0 """ from core.user import User user = User("wangshanglang", 100, "shen_zhen") user.show_info()
def parse(self): def get_agree(line): if "Strongly Agree" in line: return 5 elif "Strongly Disagree" in line: return 1 elif "Disagree" in line: return 2 elif "Neutral" in line: return 3 elif "Agree" in line: return 4 else: return -999 with open(self.survey_uri) as survey_data: current_question = 0 current_user = None for line in survey_data: line = line.strip() if len(line) == 0: continue if line[:5] == "PAGE ": continue # Parse current question if line[0] == "Q" and (line[2] == ":" or line[3] == ":"): qid = line.split(":")[0][1:] try: qid = int(qid) if qid in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]: current_question = qid else: print "ERROR: Question ID Parse Failed", line except: print "ERROR: Question ID Parse Failed", line # Question 1 elif "What is your DS ProD member number?" in line: user_id = line.split(" ")[-1].replace("/", "") for x_user in self.users: if x_user.user_id == user_id: print "SOMEONE TOOK THIS TWICE", user_id exit current_user = User(user_id) self.users.add(current_user) elif "what you put on Meetup" in line: current_user.name = line[line.find(")") + 1:].strip() # elif "Go change your DS ProD Meetup photo" in line: # self.users[user_id]["photo"] = ... #TODO:hit API to grab pic, to send to match? elif current_question == 2: current_user.career_stage = line elif current_question == 3: skills = line.split("-") for level in current_user.methods.get_levels(): level_txt = current_user.methods.txt(level) if level_txt in line: skill = skills[0].strip()[:-1] current_user.broad_skills.append_at_level( level, skill) continue elif current_question == 4: for level in current_user.geogs.get_levels(): level_txt = current_user.geogs.txt(level) geog = line[:line.find(level_txt)].strip() if level_txt in line: current_user.geogs.append_at_level(level, geog) if line[:5] == "Other": current_user.geogs.append_at_level( "Other", line[line.find(")") + 1:].strip()) elif current_question == 5: current_user.gender = line elif current_question == 6: for level in current_user.skills.get_levels(): level_txt = current_user.skills.txt(level) if level_txt in line: skill = line[:line.find(level_txt)].strip() current_user.skills.append_at_level(level, skill) continue elif current_question == 7: if "Respondent skipped this question" in line: continue if "n/a" in line: continue slen = len("Software 1 ") package = line[slen:].strip() current_user.software.append(package) elif current_question == 8: for level in current_user.methods.get_levels(): level_txt = current_user.methods.txt(level) if level_txt in line: skill = line[:line.find(level_txt)].strip() current_user.methods.append_at_level(level, skill) continue elif current_question == 9: response = line[11:] if line[:8] == "Analysis": current_user.analysis.append(response) elif line[:8] == "Industry": current_user.industry.append(response) elif current_question == 10: if "In my industry" in line: current_user.prefs.append_at_level( get_agree(line), "industry") if "That I can mentor" in line: current_user.prefs.append_at_level( get_agree(line), "i_mentor") if "At my skill level" in line: current_user.prefs.append_at_level( get_agree(line), "at_skill_level") if "That will mentor me" in line: current_user.prefs.append_at_level( get_agree(line), "mentor_me") if "That are quite similar to me" in line: current_user.prefs.append_at_level( get_agree(line), "similar") if "That are quite different from me" in line: current_user.prefs.append_at_level( get_agree(line), "different") for user in self.users: print user return len(self.users) > 0
from .helpers import is_in from core.user import User from core.types import * model = User() base = User() model.age = 22 assert model.matching_rate(base) == 1, "Age" model.age = 25 assert model.matching_rate(base) == 0.9, "Age" model.age = 35 assert model.matching_rate(base) == 0.8, "Age" model.age = 45 assert model.matching_rate(base) == 0.7, "Age" model.age = 55 assert model.matching_rate(base) == 0.6, "Age" model.age = 100 assert model.matching_rate(base) == 0.5, "Age" model.age = base.age model.hardness_points = { "extreme": 0.33933333334, "soft": 0.46666666666, "hard": 0.194 } assert is_in(model.matching_rate(base), 0.78, 0.82), "Hardness" model.hardness_points = {"hard": 0.05, "extreme": 0.9, "soft": 0.05} assert is_in(model.matching_rate(base), 0.52, 0.55), "Hardness" model.hardness_points = base.hardness_points.copy()
def create_user(username, password, permissions=DEFAULT_PERMISSIONS): u = User(username=username, permissions=permissions) u = set_password(u, password) return u.save()
def create_user(saml_name_id, saml_user_data): u = User(username=saml_name_id) u.save() u = adjust_permissions(u, saml_user_data) return u
def handle(self): while True: # login_auth headers_login_auth = self.recv_data_packet_server() if headers_login_auth['operation'] == '0': # 退出 break elif headers_login_auth['operation'] == '1': # 登录 account = headers_login_auth['account'] password = headers_login_auth['password'] ret_login = User.login_auth(account, password) # ret_login true false if ret_login: self.send_state_code_server(1) break else: self.send_state_code_server(0) elif headers_login_auth['operation'] == '2': # 注册 account = headers_login_auth['account'] password = headers_login_auth['password'] ret_register = User.register( account, password) # ret_register true false if ret_register: self.send_state_code_server(1) break else: self.send_state_code_server(0) if headers_login_auth['operation'] != '0': # 当用户认证成功进入此模块 user = User(headers_login_auth['account']) while True: # operation_choice headers_operation = self.recv_data_packet_server() if headers_operation['operation'] == '0': # exit break elif headers_operation['operation'] == '1': # enter_upper_contents,进入上层目录 ret_data = user.enter_upper_contents() self.send_data_server(ret_data) elif headers_operation['operation'] == '2': # enter_lower_contents,进入下层目录 lower_contents_name = headers_operation[ 'lower_contents_name'] ret_data = user.enter_lower_contents(lower_contents_name) self.send_data_server(ret_data) elif headers_operation['operation'] == '3': # create_folder,创建新文件夹 new_folder_name = headers_operation['new_folder_name'] ret_state = user.create_folder(new_folder_name) ret_state = 1 if ret_state else 0 self.send_state_code_server(ret_state) elif headers_operation['operation'] == '4': # clear_empty_file,清空空文件和空文件夹 ret_data = user.clear_empty_file() self.send_data_server(ret_data) elif headers_operation['operation'] == '5': # show_file,展示当前文件夹内的文件信息 ret_data = user.show_file() self.send_data_server(ret_data) elif headers_operation['operation'] == '6': # uploading_files,上传文件 self.recv_data_file_server(headers_operation, user) elif headers_operation['operation'] == '7': # download_files,下载文件,未实现 pass self.request.close()