def create_new_profile(self): profile_name = None profile_faction = None layout = self.get_profile_layout(new=True) window = sg.Window("New profile", layout=layout, force_toplevel=True, modal=True) window.Finalize() while True: event, values = window.read() if event == "save": profile_name = values["name"] self.user_profile = UserProfile(profile_name, profile_faction) if not self.user_profile.save(values): overwrite = sg.popup_ok_cancel("Profile name already exists. Overwirte?") if overwrite == 'OK': self.user_profile.overwrite() break else: break elif event == "faction": profile_faction = values["faction"] elif event in {sg.WIN_CLOSED, "Cancel"}: window.close() return if values and values["name"] and profile_faction: window["save"].Update(disabled=False) elif values and not values["name"]: window["save"].Update(disabled=True) window.close() return copy.deepcopy(self.user_profile)
def insertProfile(self, profile): info = self.splitProfile(profile) print(type(info)) import hashlib profile = UserProfile(username=info['username'], password=hashlib.sha224( str.encode(info['password'])).hexdigest(), categories=info['categories'], sources=info['sources']) profile = profile.getUserProfile() id = self.dbOperation.dbInsert(profile, 'profiles') print('OK:', id) return str(id)
def get_serialized_point_ranks(): points = UserPoints.query().order(-UserPoints.all_time_total).fetch(10) user = users.get_current_user() user_id = "nope" if (user is not None): user_id = user.user_id() ranks = [] for point in points: profile = UserProfile.get_or_insert(point.user_id, user_id=point.user_id) result = { "p": point.all_time_total, "n": profile.sanitized_visible_name() } if (user_id == point.user_id): result["s"] = True ranks.append(result) return json.dumps({ "error": False, "ranks": ranks, "startRank": 1 })
def setUp(self): with open("profile_example.json") as json_file: self._profiles_json = json.load(json_file) self._profiles = [ UserProfile(data) for data in self._profiles_json.values() ]
def retrieve_user_profiles(self, user_profile_url): raw_html = download_url(user_profile_url) profile_soup = BeautifulSoup.BeautifulSoup(raw_html, convertEntities=BeautifulSoup.BeautifulSoup.HTML_ENTITIES) user_profile = UserProfile(profile_soup, user_profile_url) for friend in user_profile.friends: self.urls_queue.put(friend.friend_url, block=False) return user_profile
def test_a_check_post(self): url = self.login_and_post() title_article = (self.post['title']) body_Article = (self.post['body']) check = CheckPost(self.driver) title, body = check.check_post(url) self.assertEqual(title_article, title) self.assertEqual(body_Article, body) profile = UserProfile(self.driver) last_published_article = profile.user_profile_post() self.assertEqual(title_article, last_published_article) add = AddComment(self.driver, self.comment) comment_add = add.add_comment() self.assertEqual(self.comment, comment_add)
def __init__(self, user_profile): self.prepared_data = dict() self.url = None self.method = 'GET' self.headers = {} self.profile = UserProfile(**user_profile) self.logger = logging.getLogger(__name__) self.response = ResponseHandler({ "success": False, "ok": False, "content": '' })
def handle_message(self, message): if not self.p2p_state == 'UNREGISTERED': self.mob.get_user_by_id(self.id).update_nickname(message['from']) text = message['text'] if self.p2p_state == 'AWAIT_PROMISE': if not self.promise_exists(): self.mob.get_user_by_id(self.id).add_promise( date.today().toordinal(), text) self.p2p_state = 'IDLE' return words.promise_accept, words.menu, else: self.p2p_state = 'IDLE' return words.promise_decline.format( self.mob.get_user_by_id(self.id).promises[ date.today().toordinal()]), words.menu if self.p2p_state == 'AWAIT_STATUS': if self.get_status() in {-1, 2, 3}: self.p2p_state = 'IDLE' return words.status_decline, words.menu, if text.lower().replace(' ', '') == 'да': self.set_status(3) self.p2p_state = 'IDLE' return words.status_success, words.menu, if text.lower().replace(' ', '') == 'нет': self.set_status(2) self.p2p_state = 'IDLE' return words.status_fail, words.menu, return words.status_unknown, words.status_listen, if self.p2p_state == 'UNREGISTERED': if text.lower().replace(' ', '') == '/participate': self.p2p_state = 'IDLE' if not self.mob.user_id_present(id): self.mob.users.append(UserProfile(self.id)) return words.registered, words.menu, return words.greet, if self.p2p_state == 'IDLE': if text == '/stats': return self.mob.get_user_by_id(self.id).stats_str(), if text == '/promise': if not self.promise_exists(): self.p2p_state = 'AWAIT_PROMISE' return words.promise_listen, return words.promise_decline.format( self.mob.get_user_by_id(self.id).promises[ date.today().toordinal()]['text']), words.menu if text == '/complete': if not self.promise_exists(): return words.no_promise, if self.get_status() in {0, 1}: self.set_status(3) return words.status_success, words.menu, return words.status_decline, words.menu, return words.menu,
def set_user_name(): try: new_name = request.forms.get('name') if (new_name is None): return {"error": True, "errorMessage": "'new_name' param must be set."} if (len(new_name) < min_visible_name_length): return { "error": True, "errorMessage": "Name can't be less than " + str(min_visible_name_length) + " characters."} if (len(new_name) > max_visible_name_length): return { "error": True, "errorMessage": "Name can't be more than " + str(max_visible_name_length) + " characters."} if (not visible_name_pattern.match(new_name)): return {"error": True, "errorMessage": "Name must be alphanumeric."} user = users.get_current_user() id_to_change = str(user.user_id()) # if we're an admin, allow changing anyone's name with the right id if (user and users.is_current_user_admin() and request.forms.get('id') is not None): id_to_change = request.forms.get('id') # get profile and set new name profile = UserProfile.get_or_insert(id_to_change, user_id=id_to_change, visible_name=new_name) profile.visible_name = new_name profile.put() return {"error": False } except Exception as e: return process_exception(e)
def __init__(self, user_profile): """Initialization method for Delhivery base class, which sets credentials for using Delhivery API Args: user_profile - This will be the dictionary containing client name and api token. """ self.prepared_data = None self.url = None self.method = 'GET' self.headers = {} self.profile = UserProfile(**user_profile) self.logger = logging.getLogger(__name__) self.response = ResponseHandler({ "success": False, "ok": False, "content": '' })
def test_username(self): test_data = [(UserProfile(data), data["username"]) for data in self._profiles_json.values()] for profile, username in test_data: self.assertEqual(profile.get_username(), username)
def __init__(self): self.default_user = UserProfile() self.user_profile = UserProfile()
class GUIUserProfile(): def __init__(self): self.default_user = UserProfile() self.user_profile = UserProfile() def create_new_profile(self): profile_name = None profile_faction = None layout = self.get_profile_layout(new=True) window = sg.Window("New profile", layout=layout, force_toplevel=True, modal=True) window.Finalize() while True: event, values = window.read() if event == "save": profile_name = values["name"] self.user_profile = UserProfile(profile_name, profile_faction) if not self.user_profile.save(values): overwrite = sg.popup_ok_cancel("Profile name already exists. Overwirte?") if overwrite == 'OK': self.user_profile.overwrite() break else: break elif event == "faction": profile_faction = values["faction"] elif event in {sg.WIN_CLOSED, "Cancel"}: window.close() return if values and values["name"] and profile_faction: window["save"].Update(disabled=False) elif values and not values["name"]: window["save"].Update(disabled=True) window.close() return copy.deepcopy(self.user_profile) def edit_user_profile(self, user_profile): profile_name = user_profile.profile_name profile_faction = user_profile.profile_faction if profile_name: self.user_profile = user_profile layout = self.get_profile_layout() window = sg.Window("New profile", layout=layout, force_toplevel=True, modal=True) window.Finalize() window["save"].Update(disabled=False) window["name"].Update(profile_name, disabled=True) window["faction"].Update(profile_faction, disabled=True) while True: event, values = window.read() if event == "save": if not self.user_profile.save(values): overwrite = sg.popup_ok_cancel("Save changes?") if overwrite == 'OK': self.user_profile.overwrite() else: break elif event in {sg.WIN_CLOSED, "Cancel"}: window.close() return window.close() return copy.deepcopy(self.user_profile) else: return self.create_new_profile() def load_user_profile(self): layout = self.get_load_layout() window = sg.Window("Load profile", layout=layout, force_toplevel=True, modal=True) window.Finalize() while True: event, values = window.read() if event == "load": profile_name = values["listbox"][0] self.user_profile.load(profile_name) break elif event in {sg.WIN_CLOSED, "Cancel"}: window.close() return window.close() return copy.deepcopy(self.user_profile) def get_skills_layout(self, new=False): if new: skill_levels = self.default_user.get_skills_data() else: skill_levels = self.user_profile.get_skills_data() skills_data = self.default_user.get_full_skills_data() layout = [] for skill_group in skills_data: skill_types = skills_data[skill_group] skill_types_layout = [] skill_group_layout = [] for skill_type in skill_types: skill_names = skill_types[skill_type] skill_names_layout = [[sg.Text(skill_name, size=(50, 1))] + [sg.Combo([0, 1, 2, 3, 4, 5], key=skill_name, size=(10, 1), default_value=skill_levels[skill_name])] for skill_name in skill_names] skill_types_layout.append(sg.Tab(skill_type, layout=skill_names_layout)) skill_group_layout.append(sg.TabGroup([skill_types_layout])) layout.append(sg.Tab(skill_group, [skill_group_layout])) return [sg.TabGroup([layout])] def get_profile_layout(self, new=False): name_layout = [sg.Text('Name: ', size=(8, 1))] + [sg.InputText("", key="name", enable_events=True, size=(20, 1))] factions_layout = [sg.Text('Faction: ', size=(8, 1))] + [sg.Combo(FACTIONS, key="faction", enable_events=True, size=(20, 1))] save_button = sg.Button("Save", key="save", disabled=True) cancel_button = sg.Cancel() buttons_layout = [save_button] + [cancel_button] skills_layout = self.get_skills_layout(new=new) layout = [ name_layout, factions_layout, skills_layout, buttons_layout, ] return layout def get_load_layout(self): available_profiles = glob("saved_profiles/*.yaml") available_profiles_list = [profile.replace("\\", "/").split("/")[-1].split(".")[0] for profile in available_profiles] load_button = sg.Button("Load", key="load") cancel_button = sg.Cancel() available_profiles_layout = [ [sg.Listbox(available_profiles_list, enable_events=True, default_values=available_profiles_list[0], select_mode="single", key="listbox", size=(25, 10))], [load_button] + [cancel_button] ] return available_profiles_layout