def _save_level(world, challengeNo): old_xp = calculate_xp() needsToSave = False groups = load_app_state_variable(APP_NAME, 'groups') # We might need to load the worlds file here so that we're sure that # no one is abusing the API from the OS if groups is None: groups = {} if world in groups: if groups[world]['challengeNo'] < challengeNo: groups[world]['challengeNo'] = challengeNo needsToSave = True else: groups[world] = {'challengeNo': challengeNo} needsToSave = True if needsToSave: save_app_state_variable_with_dialog(APP_NAME, 'groups', groups) new_xp = calculate_xp() return str(new_xp - old_xp)
def _save_level(level): old_xp = calculate_xp() value = int(level) - 1 save_app_state_variable_with_dialog(APP_NAME, 'level', value) new_xp = calculate_xp() return str(new_xp - old_xp)
def upload_profile_stats(self): profile = load_profile() data = dict() # xp data['xp'] = calculate_xp() # version try: data['version'] = profile['version'] except KeyError: logger.debug("Version field not in the data to be synced") # age try: data['birthdate'] = profile['birthdate'] except Exception: pass # gender try: gender = profile['gender'] if gender == "Boy": gender = 'm' elif gender == "Girl": gender = 'f' elif gender == "Wizard": gender = 'x' data['gender'] = gender except Exception: pass # avatar_generator data, files = self._prepare_avatar_gen(profile, data) # app states stats = dict() for app in get_app_list(): if not is_private(app): stats[app] = load_app_state(app) # append stats data['stats'] = stats # Uploading profile stats success, text, response_data = request_wrapper( 'put', '/users/profile', data=json.dumps(data), headers=content_type_json, session=self.session) if not success: logger.error("Uploading of the profile data failed") return False, text if files: # Uploading avatar assets success, text, response_data = request_wrapper( 'put', '/users/profile', session=self.session, files=files) # requests doesn't close the file objects after sending them, so # we need to tidy up self._tidy_up_avatar_files(files) if not success: logger.error("Uploading of the avatar assets failed") return False, text return self.download_profile_stats(response_data)