def refresh_notifications(self): rv = True error = None next_page = 0 notifications = [] while next_page is not None: success, text, data = request_wrapper( 'get', '/notifications?read=false&page={}'.format(next_page), session=self.session ) if not success: rv = False error = text break for entry in data['entries']: if entry['read'] is False: n = self._process_notification(entry) if n: notifications.append(n) try: next_page = data['next'] except: break if rv: profile = load_profile() profile['notifications'] = notifications save_profile(profile) return rv, error
def refresh_notifications(self): rv = True error = None next_page = 0 notifications = [] while next_page is not None: success, text, data = request_wrapper( 'get', '/notifications?read=false&page={}'.format(next_page), session=self.session) if not success: rv = False error = text break for entry in data['entries']: if entry['read'] is False: n = self._process_notification(entry) if n: notifications.append(n) try: next_page = data['next'] except: break if rv: profile = load_profile() profile['notifications'] = notifications save_profile(profile) return rv, error
def login_register_data(data): global glob_session profile = load_profile() profile['token'] = data['session']['token'] profile['kanoworld_username'] = data['session']['user']['username'] profile['kanoworld_id'] = data['session']['user']['id'] profile['email'] = data['session']['user']['email'] # We know this field will be returned from the API even if it is empty # However we only need to store it if it has a meaningful value try: if data['session']['user']['secondary_email']: profile['secondary_email'] = data['session']['user'][ 'secondary_email'] except: profile.pop('secondary_email', None) save_profile(profile) try: glob_session = KanoWorldSession(profile['token']) return True, None except Exception as e: return False, _( "We cannot reach the Kano server. Try again in a few minutes. Error = {}" ).format(str(e))
def refresh_notifications(self): rv = True error = None next_page = 0 notifications = [] while next_page is not None: success, text, data = request_wrapper( "get", "/notifications?read=false&page={}".format(next_page), session=self.session ) if not success: rv = False error = text break for entry in data["entries"]: if entry["read"] is False: n = self._process_notification(entry) notifications.append(n) try: next_page = data["next"] except: break if rv: profile = load_profile() profile["notifications"] = notifications save_profile(profile) return rv, error
def remove_registration(): profile = load_profile() profile.pop('token', None) profile.pop('kanoworld_username', None) profile.pop('kanoworld_id', None) profile.pop('email', None) profile.pop('secondary_email', None) save_profile(profile)
def login_register_data(data): global glob_session profile = load_profile() profile['token'] = data['session']['token'] profile['kanoworld_username'] = data['session']['user']['username'] profile['kanoworld_id'] = data['session']['user']['id'] profile['email'] = data['session']['user']['email'] # We know this field will be returned from the API even if it is empty # However we only need to store it if it has a meaningful value try: if data['session']['user']['secondary_email']: profile['secondary_email'] = data['session']['user']['secondary_email'] except: profile.pop('secondary_email', None) save_profile(profile) try: glob_session = KanoWorldSession(profile['token']) return True, None except Exception as e: return False, 'We cannot reach the Kano server. Try again in a few minutes. Error = {}'.format(str(e))
def remove_token(): profile = load_profile() profile.pop('token', None) save_profile(profile)