def get_kif(): login_url = "http://web.shogidojo.net/kifu/srv/login" kifs_url = "http://web.shogidojo.net/kifu/srv/search" if not os.path.exists("user_pass.json"): pass else: users = Users().get_users() for user, password in users.items(): response = requests.post(login_url, data={ 'name': user, 'pwd': password }) cook = response.cookies kif_file_list = requests.post(kifs_url, cookies=cook.get_dict(), data={ 'from_date': '2000-1-1', "to_date": "2030-1-1", "sub": "a" }) response.text parser = KifParser() parser.feed(kif_file_list.text) parser.close() for kif_url, filename in parser.links: if not os.path.exists("static/kif"): os.mkdir("static/kif") f = open("./static/kif/" + filename + '.kif', 'w') kif_file = requests.post(kif_url, cookies=cook.get_dict()) f.write(kif_file.text) f.close()
def _search(self): if Users.user_exists(self.content['username']): self.response['key'] = Encryptor.get_public_key_as_string( Users.get_public_key(self.content['username'])) self.response['username'] = self.content['username'] else: self.status = ResponseCreator.status_codes['USER_DO_NOT_EXIST']
def __init__(self, filename): if not os.path.exists("user_pass.json"): pass else: user = Users().get_users() user_names = [ key for key, value in user.items()] [user1, user2] = re.findall(self.user_name_pattern, filename) user1 = user1[1:-1] user2 = user2[1:-1] tmp = re.sub(self.user_name_pattern, '', filename).split('_') if len(tmp) == 5: [kif_id, date, rate1, result, rate2] = tmp if user1 in user_names and result == "ox": result = "勝ち" elif user1 in user_names and result == "xo": result = "負け" elif user2 in user_names and result == "ox": result = "負け" elif user2 in user_names and result == "xo": result = "勝ち" else: result = "引き分け" [kif_id, date, rate1, rate2] = tmp user_name = user1 if user1 in user_names: rate = rate1 sengo = "先手" else: user_name = user2 rate = rate2 sengo = "後手" self.extract_info = [sengo, result, user_name, rate, filename, kif_id]
def config_user_edit(): #print(request.form) user_name = request.form.getlist("user")[0] password = request.form.getlist("password")[0] user = Users() user.add_user(user_name, password) kif() return render_template('config_user.html', users=user.get_users())
def initializeUser(self, user, DAL): if user == 'Admin!': AdminPanel().chooseAction() if user in DAL.userDatabase: user, wordObjects = Users().loadExisting(DAL, user) else: user, wordObjects = Users(user).createNew(DAL, user) return user, wordObjects
def test_add_multiple_users(self): ''' test for posibility of adding many users to user_list ''' self.new_user.add_user() test_user = Users("Moringa", "1234") test_user.add_user() self.assertEqual(len(Users.users_list), 2)
def test_users_exists(self): """ test_user_exists test case to check if we can return a boolean if we cannot find the user """ self.new_user.save_user() test_user = Users("Judy", "homeboys123") test_user.save_user() user_exists = Users.users_exist("homeboys123") self.assertTrue(user_exists)
def rate(): data = DuelData() user = Users() data.create_graph() user_names = [] for user_name, password in user.get_users().items(): data.create_user_graph(user_name) user_names.append(user_name) return render_template('rate.html', user_names=user_names)
def ensure_calendar_updated(person_id, conn, http=Http()): users = Users(conn) last_update_time = users.last_update_time(person_id) if not last_update_time or ( last_update_time and (last_update_time - datetime.utcnow()).total_seconds() < 60 * 60 * 4): return update_calendar_one_user(person_id, users, http)
def main(): Users.deserialize() server = Server('192.168.1.49', 65000) server.run() Users.serialize() # test_encryption_time() # test_hash_time() pass
def authorise_new_user(): code = request.args.get("code") state = request.args.get("state") conn = get_connection() users = Users(conn) person_id = authorise_user(code, state, conn=conn) users.add_location(person_id, "wellington") ensure_calendar_updated(person_id, conn) return render_template("done.html")
def test_user_exists(self): ''' test if a user exists or not ''' self.new_user.add_user() test_user = Users("Moringa", "1234") test_user.add_user() user_exists = Users.user_exists("Moringa","1234") self.assertTrue(user_exists)
def post(self): query_user = Users().all() user_id = self.request.get("id") user_pwd = self.request.get("pwd") delete_user = query_user.filter("id =", user_id).filter("pwd =", user_pwd) db.delete(delete_user) # view template_values = {} path = os.path.join(os.path.dirname(__file__), "../templates/deleteuser.html") self.response.out.write(template.render(path, template_values))
def test_search_username(self): ''' test finding user via username logic ''' self.new_user.add_user() test_user = Users("Moringa", "1234") test_user.add_user() found_user = Users.search_username("Moringa") self.assertEqual(found_user.login_password, test_user.login_password)
def test_save_multiple_users(self): ''' test_save_multiple_contact to check if we can save multiple contact objects to our contact_list ''' self.new_user.save_users_details() test_user = Users("john andy", "*****@*****.**", "john123") # new user test_user.save_users_details() self.assertEqual(len(Users.users_list), 2)
def _delete_account(self): username = self.content['username'] if not Users.user_exists(username): self.status = ResponseCreator.status_codes['USER_DO_NOT_EXIST'] return user = Users.get_user(username) password = Encryptor.asymmetric_decrypt_message( key=ServerSession.get_private_key(), message=self.content['password']) if user.check_password(password): Users.delete_user_account(username)
def _register(self): username = self.content['username'] if Users.user_exists(username): self.status = ResponseCreator.status_codes['LOGIN_NOT_AVAILABLE'] return password = self.content['password'] public_key = self.content['public_key'] email = self.content['email'] usr = User(username=username, password=Encryptor.hash_message(password.encode()).decode(), email=email) Users.add_user(usr) UsersToPublicKeys.add_user_public_key(username, public_key)
def _getnewmsgs(self): msg_list = [] msgs = Users.get_user(self.sender).get_undelivered_messages() while len(msgs) != 0: msg = msgs.pop() msg_list.append(msg.as_dict()) self.response['message_array'] = msg_list
def authenticate(username, password): #No longer needed since findbyuser in user class will take care of that #user= username_mapping.get(username,None) user = Users.findByUserName(username) #if user and user.password==password: if user and safe_str_cmp(user.password, password): return user
def addUser(self, baekjoonId, nickName, getReinforceCount, rank, solvedProblem, wrong): ## 유저 중복되는지도 체크해줘야함 joonUsers = Data.child("Baejoon").child(baekjoonId).get() if joonUsers != None: return -1 users = Users(baekjoonId, getReinforceCount, solvedProblem, rank, wrong) # 마지막요소 디스코드랭킹인데 이건 따로 구해야함 ㅇㅋ? Data.child("Users").child(nickName).set(json.loads(users.toJSON())) Data.child("Users").child(nickName).child("아이템").child("롱소드").set(0) Data.child("Baejoon").child(baekjoonId).set(1) return 0
def _save(self): request_content = json.loads(self.content) if request_content['response_content']['message_array']: for msg in request_content['response_content']['message_array']: msg = UserMessage.parse_from_dict(json.loads(self.content)) message_sender = Users.get_user(msg.sender) message_sender.add_msg_to_dialog(msg.recipient, msg)
def authenticate_user(user_name, password): """ Function to authenticate users when they login :param user_name: :param password: """ return Users.authenticate_user(user_name, password)
def post(self): receiver_mail = self.request.get("email") receiver = Users.query(Users.email == receiver_mail).get() if not receiver: params = { "notification": "Uporabnik " + receiver_mail + " ne obstaja.", "alert_type": "danger" } return self.render_template("bmail.html", params=params) if receiver_mail == self.current_user().email: params = { "notification": "Sebi ne morete poslati sporočila !!!", "alert_type": "danger" } return self.render_template("bmail.html", params=params) message = self.request.get("message") Messages(message=message, sender=self.current_user().key, receiver=receiver.key).put() params = { "notification": "Uspešno poslano za " + receiver_mail, "alert_type": "success" } return self.render_template("bmail.html", params=params)
def delete(): if request.method == 'POST': print(request.form) clients = Users.delete_user(int(request.form["number"])) return render_template('delete_user.html', title="Удаление пользователя", menu=menu)
def _getallmsgs(self): msg_list = [] dialogs = Users.get_user(self.sender).get_all_dialogs() for k, v in dialogs.items(): for msg in v.get_messages(): msg_list.append(msg.as_dict()) self.response['message_array'] = msg_list
def setup(): print '\n**** service initialization ****\n' global courseobj, userobj, sessionobj userobj = Users() courseobj = Course() connection = Connection('localhost', 27017) sessionobj = Session(connection.doccdb)
def analitics(): data = DuelData() user = Users() analitics = Analitics(data.get_data()).get_analitics() t = sorted(analitics.items(), key=lambda x: x[0]) return render_template('analitics.html', analitics=analitics)
class TestUser(unittest.TestCase): """ Test class that defines test cases for the user class behaviours. Args: unittest.TestCase: TestCase class that helps in creating test cases """ def setUp(self): """ Set up method to run before each test cases. """ self.new_user = Users("andyjohn", "*****@*****.**", "andy123") # create user object def test__init__(self): """ test_init test case to test if the object is initialized properly """ self.assertEqual(self.new_user.username, "andyjohn") self.assertEqual(self.new_user.email, "*****@*****.**") self.assertEqual(self.new_user.password, "andy123") def tearDown(self): """ tearDown method that does clean up after each test case has run. """ Users.users_list = [] def test_save_users_details(self): """ Test to check if the new users info is saved into the users list """ self.new_user.save_users_details() self.assertEqual(len(Users.users_list), 1) def test_save_multiple_users(self): ''' test_save_multiple_contact to check if we can save multiple contact objects to our contact_list ''' self.new_user.save_users_details() test_user = Users("john andy", "*****@*****.**", "john123") # new user test_user.save_users_details() self.assertEqual(len(Users.users_list), 2)
def __init__(self, file_name='speech.wav'): self.file_name = file_name self.running = True self.users = Users() self.msg = Message() self.conversation = None self.sr = IdentificationServiceHttpClientHelper( os.environ.get('MSKEY1', '')) self.recorder = Recorder() self.commands = { 'enroll new profile': self.enroll, 'start conversation': self.start_conversation, 'sign into conversation': self.sign_into_conversation, 'stop conversation': self.close_conversation, 'close application': self.stop_running, 'clear profiles': self.clear_profiles }
class TestUsers(unittest.TestCase): """ Test class that defines test cases for the users class behaviours Args: unittest.TestCase: TestCase class that helps in creating test cases """ def setUp(self): """ Set up method to run before each test cases. """ self.new_user = Users("Judy", "homeboys123") def tearDown(self): """ cleans up after every test has been done """ Users.users_list = [] def test_init(self): """ Test case to test if the object is initialized properly """ self.assertEqual(self.new_user.user_name, "Judy") self.assertEqual(self.new_user.password, "homeboys123") def test_new_user_creation(self): """ Tests if new users account has been created """ self.new_user.save_user() self.assertEqual(len(Users.users_list), 1) def test_users_exists(self): """ test_user_exists test case to check if we can return a boolean if we cannot find the user """ self.new_user.save_user() test_user = Users("Judy", "homeboys123") test_user.save_user() user_exists = Users.users_exist("homeboys123") self.assertTrue(user_exists)
def _authenticate(self): username = self.content['username'] if not Users.user_exists(username): self.status = ResponseCreator.status_codes['USER_DO_NOT_EXIST'] return user = Users.get_user(username) password = Encryptor.asymmetric_decrypt_message( key=ServerSession.get_private_key(), message=self.content['password']) if user.check_password(password): key = Encryptor.generate_symmetric_key() ServerSession.add_client_session_key(user.get_username(), key) pub_k = UsersToPublicKeys.get_public_key(username) print(username, ' session key ', key) encrypted_key = Encryptor.asymmetric_encrypt_message(key=pub_k, message=key) self.response = {'key': encrypted_key} else: self.status = ResponseCreator.status_codes['WRONG_PASSWORD']
def generate(klass, name = None): loc = klass(name, make_place_desc(), set(random.sample(['N','E','W','S'], random.randint(1,3))) ) if random.randint(0,10) > 1: orc = User.generate(name + 'orc') loc.enemies.append(orc) Users.instance()[orc.name] = orc return loc
def post(self): new_user = Users() new_user.id = self.request.get("id") new_user.pwd = self.request.get("pwd") new_user.email = self.request.get("mail") new_user.put() self.redirect("/createuser")
def users_test(): users = Users() users.add_user(1, "milo@com", "tratata", "Katya", "Korolchuk", "developer", "picture", "active")