def add_sig(): ##print("Adding a sig...") # Getting the sig info json_input = request.data json_data = json.loads(json_input.decode('utf-8')) ### Authenticating the player # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Building data from the given info mydb = init_mysql("db_map") cursor = mydb.cursor() ### Creating the log entry log_entry = [] log_entry_create = {"info": "Created sig", "user": json_data['character_id'], "date": datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")} log_entry.append(log_entry_create) ### Converting to string log_entry = json.dumps(log_entry) insert = "INSERT INTO tb_sig (sig_id_num, sig_id_letter, sig_type, sig_name, sig_wormhole_data, sig_system, sig_age, sig_log, sig_mass, sig_display_lifespan) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" data = [json_data['sig_id_num'], json_data['sig_id_letter'], json_data['sig_type'], json_data['sig_name'], str(json_data['sig_wormhole_data']), json_data['sig_system'], json_data['sig_age'], log_entry, json_data['sig_mass'], json_data['sig_display_lifespan']] cursor.execute(insert, data) mydb.commit()
def get_search(): print("Getting all of the search data") # Getting the sig info json_input = request.data json_data = json.loads(json_input.decode('utf-8')) ### Authenticating the player # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") connector = init_mysql("db_map") cursor = connector.cursor() SELECT_ALL_SEARCH = "SELECT * FROM tb_search" cursor.execute(SELECT_ALL_SEARCH) result = cursor.fetchall() result_encoded = get_format_from_raw_full(result) throw_json_success("Success", result_encoded)
def add_search(): print("Adding a new search entry") # Getting the sig info json_input = request.data json_data = json.loads(json_input.decode('utf-8')) ### Authenticating the player # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") connector = init_mysql("db_map") cursor = connector.cursor() # Adding a new sig ADD_NEW_SEARCH = "INSERT INTO tb_search (search_name, search_character) VALUES (%s, %s)" cursor.execute(ADD_NEW_SEARCH, (json_data['search_name'], json_data['character_id'])) connector.commit() throw_json_success("Success", {})
def get_current_tokens(): print("Getting all available tokens") json_input = request.data.decode('utf-8') json_data = json.loads(json_input) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") ### Connecting with our database connector = init_mysql("db_cctv") cursor = connector.cursor() SELECT_TOKEN = "SELECT * FROM tb_cctv_token" cursor.execute(SELECT_TOKEN, ) result = list(cursor.fetchall()) new_result = [] for element in result: new_element = [] for value in element: if isinstance(value, datetime.datetime): value = date_to_string(value) new_element.append(value) new_element = tuple(new_element) new_result.append(new_element) print(new_result) return throw_json_success("Success", new_result)
def get_new_auth(): print("Getting a new auth code for the stream data") # Getting the characters location # Checking how hardcore we are on updating json_input = request.data.decode('utf-8') json_data = json.loads(json_input) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") ### Okay, we will now proceed to generate a new authentication token.... new_token = gen_random_string(8) ### Inserting into our database connector = init_mysql("db_cctv") cursor = connector.cursor() INSERT_CCTV_TOKEN = "INSERT INTO tb_cctv_token (cctv_token_code, cctv_init_character) VALUES (%s, %s)" cursor.execute(INSERT_CCTV_TOKEN, (new_token, json_data['character_id'])) connector.commit() return throw_json_success("Success", new_token)
def get_settings(): print("Getting character settings") ### Authenticating user json_input = request.data json_data = json.loads(json_input.decode('utf-8')) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") mydb = init_mysql("db_character") select = "SELECT * FROM tb_character_setting WHERE character_id = %s" cursor = mydb.cursor() cursor.execute(select, (json_data['character_id'], )) result_raw = cursor.fetchall() if len(result_raw) <= 0: init_setting_file(json_data['character_id'], cursor, mydb) cursor.execute(select, (json_data['character_id'], )) result_raw = cursor.fetchall() result = get_format_from_raw(result_raw, cursor) result['wormhole_mask'] = json.loads(result['wormhole_mask']) return throw_json_success(200, result) else: result = get_format_from_raw(result_raw, cursor) result['wormhole_mask'] = json.loads(result['wormhole_mask']) return throw_json_success(200, result)
def delete_sig(): ##print("Deleting a sig...") # Getting the sig info json_input = request.data json_data = json.loads(json_input.decode('utf-8')) ### Authenticating the player # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Building data from the given info mydb = init_mysql("db_map") cursor = mydb.cursor() sig_delete_list = json_data['sig_id_list'] ##print(sig_delete_list) for sig_delete in sig_delete_list: if sig_delete_list[sig_delete] == 1: delete = "UPDATE tb_sig SET sig_status = 1 WHERE sig_id = %s" cursor.execute(delete, (sig_delete,)) mydb.commit()
def get_sigs(): ##print("Getting all sigs :O") # Getting the sig info json_input = request.data json_data = json.loads(json_input.decode('utf-8')) ### Authenticating the player # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Building data from the given info mydb = init_mysql("db_map") cursor = mydb.cursor() select = "SELECT * FROM tb_sig WHERE sig_status = 0" cursor.execute(select) result_raw = cursor.fetchall() result = get_format_from_raw_full(result_raw, cursor) result = encode_datetime(result) return throw_json_success("success", result)
def get_character(): json_input = request.data.decode('utf-8') json_data = json.loads(json_input) ### Authenticating the player # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") ### Okay if we have authenticated, lets get all of the relevant information get_character_query = "SELECT tb_character_type.*, tb_character.character_id, tb_character.character_type FROM tb_character INNER JOIN tb_character_type WHERE tb_character.character_id = %s AND character_type_id = character_type" ### Connecting mydb = init_mysql("db_character") cursor = mydb.cursor() cursor.execute(get_character_query, (json_data['character_id'], )) result_raw = cursor.fetchall() print(result_raw) result_full = get_format_from_raw(result_raw, cursor) return throw_json_success("Success", result_full)
def add_eft_fit(): json_input = request.data.decode('utf-8') json_data = json.loads(json_input) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") character_id, character_auth_code = json_data['character_id'], json_data[ 'character_auth_code'] # Converting from EFT to ESI eft_fit = json_data['eft_fit'] esi_fit = convert_eft_to_esi(eft_fit) esi_fit_str = json.dumps(esi_fit) fit_attributes = json.dumps(json_data['fit_attributes']) fit_title = json_data['fit_title'] # Saving it into our database mydb = init_mysql("db_fitting") cursor = mydb.cursor() skill_type_id, skill_type_name = (calculate_fit_skill_reqs(esi_fit, mydb)) fitting_add = "INSERT INTO tb_fitting (fit_attributes, fit_esi, fit_eft, character_id, fit_title, fit_skillreqs_typeid, fit_skillreqs_typename) VALUES (%s, %s, %s, %s, %s, %s, %s)" cursor.execute( fitting_add, (fit_attributes, esi_fit_str, eft_fit, json_data['character_id'], fit_title, json.dumps(skill_type_id), json.dumps(skill_type_name))) mydb.commit() return throw_json_success("success", "Fit inserted")
def get_eve_all(): json_input = request.data.decode('utf-8') json_data = json.loads(json_input) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") character_id, character_auth_code = json_data['character_id'], json_data[ 'character_auth_code'] # Attempting to load all of the eve fits associated with this account # Given the character ID and character auth code, lets get (or generate) and access token sso_id = auth_character(character_id, character_auth_code) # Checking for error if sso_id == -1: return throw_json_error(500, "Invalid character authentication code") # Otherwise, lets get that token access_token = get_access_token(character_id, sso_id) # Now that we have an access token, lets begin working with it # First we will get the players exact location result_fit = api_call_get("characters/" + str(character_id) + "/fittings/", { "character_id": character_id, "token": access_token }) # Getting the solar system ID and the structure ID result_fit_content = json.loads(result_fit.content.decode('utf-8')) # Converting each fit over to EFT style fitting output_eft = [] for fit in result_fit_content: output_eft.append(convert_esi_to_eft(fit)) return throw_json_success("success", output_eft)
def add_wormhole_mask(): print("Getting character settings") ### Authenticating user json_input = request.data json_data = json.loads(json_input.decode('utf-8')) print(json_data) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") mydb = init_mysql("db_character") select = "SELECT * FROM tb_character_setting WHERE character_id = %s" cursor = mydb.cursor() cursor.execute(select, (json_data['character_id'], )) result_raw = cursor.fetchall() result = get_format_from_raw(result_raw, cursor) print(result) wormhole_mask = json.loads(result['wormhole_mask']) ### Appending the system by system name system_name = json_data['system_name'] system_nickname = json_data['system_nickname'] system_id = get_solar_system_id_from_name(system_name) ### Using this, we are rebuilding it new_tag = { "systemName": system_name, "systemID": system_id, "systemNickname": system_nickname } wormhole_mask.append(new_tag) wormhole_mask = json.dumps(wormhole_mask) print(wormhole_mask) update = "UPDATE tb_character_setting SET wormhole_mask = %s WHERE character_id = %s" cursor.execute(update, (wormhole_mask, json_data['character_id'])) mydb.commit() select = "SELECT * FROM tb_character_setting WHERE character_id = %s" cursor.execute(select, (json_data['character_id'], )) result_raw = cursor.fetchall() result = get_format_from_raw(result_raw, cursor) result['wormhole_mask'] = json.loads(result['wormhole_mask']) return throw_json_success(200, result)
def import_skills(character_id, character_auth_code): # This should be ran as part of the auth process but it can also be triggered normally # Given the character ID and character auth code, lets get (or generate) and access token sso_id = auth_character(character_id, character_auth_code) # Checking for error if sso_id == -1: return throw_json_error(500, "Invalid character authentication code") # Otherwise, lets get that token access_token = get_access_token(character_id, sso_id) # Next, we will get the players ship result_skill = api_call_get("characters/" + str(character_id) + "/skills/", {"character_id": character_id, "token": access_token}) print(result_skill)
def delete_wormhole_mask(): print("Getting character settings") ### Authenticating user json_input = request.data json_data = json.loads(json_input.decode('utf-8')) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") mydb = init_mysql("db_character") select = "SELECT * FROM tb_character_setting WHERE character_id = %s" cursor = mydb.cursor() cursor.execute(select, (json_data['character_id'], )) result_raw = cursor.fetchall() result = get_format_from_raw(result_raw, cursor) print(result) wormhole_mask = json.loads(result['wormhole_mask']) ### Getting the index we need to delete index_track = 0 for entry in wormhole_mask: system_name = entry['systemName'] if system_name == json_data['system_name']: break index_track = index_track + 1 wormhole_mask.pop(0) wormhole_mask = json.dumps(wormhole_mask) update = "UPDATE tb_character_setting SET wormhole_mask = %s WHERE character_id = %s" cursor.execute(update, (wormhole_mask, json_data['character_id'])) mydb.commit() select = "SELECT * FROM tb_character_setting WHERE character_id = %s" cursor.execute(select, (json_data['character_id'], )) result_raw = cursor.fetchall() result = get_format_from_raw(result_raw, cursor) result['wormhole_mask'] = json.loads(result['wormhole_mask']) return throw_json_success(200, result)
def delete_tokens(): print("Deleting given token") json_input = request.data.decode('utf-8') json_data = json.loads(json_input) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") token_ids = json_data['token_delete_array'] ### Converting for token_id in token_ids: print(token_id) ### Connecting with our database connector = init_mysql("db_cctv") cursor = connector.cursor() DELETE_CCTV_TOKEN = "DELETE FROM tb_cctv_token WHERE cctv_token_id = %s" cursor.execute(DELETE_CCTV_TOKEN, (token_id,)) connector.commit() SELECT_TOKEN = "SELECT * FROM tb_cctv_token" cursor.execute(SELECT_TOKEN, ) result = list(cursor.fetchall()) new_result = [] for element in result: new_element = [] for value in element: if isinstance(value, datetime.datetime): value = date_to_string(value) new_element.append(value) new_element = tuple(new_element) new_result.append(new_element) print(new_result) return throw_json_success("Success", new_result)
def get_chain(): #print("Getting the users full chain") json_input = request.data json_data = json.loads(json_input.decode('utf-8')) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") system_name = json_data['system_name'] system_id = get_solar_system_id_from_name(system_name)['solarSystemID'] ### Getting sig data sig_data = get_sigs_internal() ### Loading the first to-visit visit_list = [] visit_list.append(system_id) parent_data = {} visisted_list = [] ### Loading from system name output = {} ### Iterate on all connections, deep search while len(visit_list) > 0: system_to_visit = visit_list.pop(0) if system_to_visit in visisted_list: continue #print("Iterating on " + str(system_to_visit)) child_data = [] ### Appending the data from the solar system id location_data = get_system_info(system_to_visit) location_name = location_data['solarSystemName'] if location_name in sig_data['sig_output_system']: ### Okay this system has sigs... ### Lets work on those real quick sig_system_data = sig_data['sig_output_system'][location_name] for sig in sig_system_data: sig_data_iterate = sig_system_data[sig] if "sig_wormhole_data" in sig_data_iterate: sig_wormhole_data = json.loads( sig_data_iterate['sig_wormhole_data']) if "wormhole_destination" not in sig_wormhole_data: continue sig_wormhole_destination = sig_wormhole_data[ 'wormhole_destination'] ### If this is a real thing, lets continue if len(sig_wormhole_destination) <= 0: continue ### Okay, we have a valid destination... ### Lets add this ID to our system solar_system_id = get_solar_system_id_from_name( sig_wormhole_destination) ### Checking for invalid systems if len(solar_system_id) <= 0: continue ### Getting the final system ID solar_system_id = solar_system_id['solarSystemID'] visit_list.append(solar_system_id) child_data.append(sig_wormhole_destination) location_data['children_by_system'] = child_data output[location_data['solarSystemName']] = location_data visisted_list.append(system_to_visit) return throw_json_success(200, output)
def add_sig_multiple(): ##print("Adding LOTS of sigs") # Getting the sig info json_input = request.data json_data = json.loads(json_input.decode('utf-8')) ### Authenticating the player # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Building data from the given info mydb = init_mysql("db_map") cursor = mydb.cursor() sig_list = json_data['sig_list'] ### THIS IS GOING TO SUCK ### ### FIRST WE NEED TO GET ALL OF THE EXISTING SIGS FOR THIS SYSTEM ### GET_SELECTED_SYSTEM_SIGS = "SELECT * FROM tb_sig WHERE sig_system = %s AND sig_status = 0" cursor.execute(GET_SELECTED_SYSTEM_SIGS, (json_data['system'],)) result = cursor.fetchall() result_full = get_format_from_raw_full(result, cursor) ### Building a map of the full sig to the sig id inside of the system this will make it easier to update later ### Okay, now lets see which one of these we need to update update_list = {} delete_list = {} sig_id_list = {} sig_list_full = {} for sig in result_full: sig_id = sig['sig_id'] sig_num = str(sig['sig_id_num']) sig_letter = str( sig['sig_id_letter']) sig_full_id = str(sig_letter)+"-"+str(sig_num) sig_id_list[sig_full_id] = sig_id sig_list_full[sig_full_id] = sig if sig_full_id in sig_list: update_list[sig_full_id] = 1 else: delete_list[sig_full_id] = 1 ### Okay, we have an update list and a list of all the new sigs... ### First, lets perform the inserts since that will be the easiest one... for sig in sig_list: ### Is this in the update? If so, we will skip if sig in update_list: ### We need to update it now... ### First thing, is lets check if we have more information to offer... current_sig = sig_list_full[sig] input_sig = sig_list[sig] input_scan_strength = input_sig['scan_strength'] index_scan_break = input_scan_strength.index('.') + 2 input_scan_strength = float(input_scan_strength[0:index_scan_break]) current_scan_strength = float(current_sig['sig_scan_strength']) current_scan_type = current_sig['sig_type'] current_scan_name = current_sig['sig_name'] input_scan_type = input_sig['group'] input_scan_name = input_sig['name'] if len(input_scan_type) <= 1: input_scan_type = "Unknown" ### Checking if our scan strength is bigger #print("Comparing scan strength of " + str(current_scan_strength) + " , " + str(input_scan_strength)) if current_scan_strength >= input_scan_strength: continue ### Checking if current_scan_strength == input_scan_strength and current_scan_type == input_scan_type and current_scan_name == input_scan_name: continue ### Checking if the new name is empty and the current name is not if (len(current_scan_type) > 0 and len(input_scan_type) < 0 ) or (len(current_scan_name) > 0 and len(input_scan_name) < 0 ): continue ### Checking if we STILL have nothing else to add... ### Okay we have more input scan strength ### Making the update sig_id = sig_id_list[sig] update_data = (input_scan_strength, input_scan_type, input_sig['name'], sig_id) UPDATE_EXISTING_SIG = "UPDATE tb_sig SET sig_scan_strength = %s, sig_type = %s, sig_name = %s WHERE sig_id = %s" cursor.execute(UPDATE_EXISTING_SIG, update_data) continue elif json_data['delete'] == "missing": ### Okay we have a sig that is NOT in the update list! And we are deleting the missing ### Lets delete this sig print("Deleting this sig of ID ") print(sig) ### Is a new sig ### Building the insert... sig_data = sig_list[sig] sig_id_letter = sig[0:3] sig_id_num = sig[4:] sig_group = sig_data['group'] if len(sig_group) <= 1: sig_group = "Unknown" sig_age = 0 if sig_group == "Wormhole": sig_age = 1440 sig_name = sig_data['name'] ### Formatting the scan strength scan_strength = 0 scan_strength_string = sig_data['scan_strength'] scan_strength_index = scan_strength_string.index(".") + 2 scan_strength = scan_strength_string[0:scan_strength_index] ### Creating the log entry log_entry = [] log_entry_create = {"info": "Created sig", "user": json_data['character_id'], "date": datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")} log_entry.append(log_entry_create) ### Converting to string log_entry = json.dumps(log_entry) insert_values = (sig_id_num, sig_id_letter, sig_group, sig_name, json_data['system'], sig_age, scan_strength, log_entry) INSERT_SIG = "INSERT INTO tb_sig (sig_id_num, sig_id_letter, sig_type, sig_name, sig_system, sig_age, sig_scan_strength, sig_log) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)" cursor.execute(INSERT_SIG, insert_values) ### Checking for those who will be deleted if json_data['delete'] == "missing": for sig in delete_list: DELETE_SIG = "DELETE FROM tb_sig WHERE sig_id = %s" cursor.execute(DELETE_SIG, (sig_id_list[sig],)) ### Committing our inserts mydb.commit()
def get_location(): # Getting the characters location # Checking how hardcore we are on updating json_input = request.data.decode('utf-8') json_data = json.loads(json_input) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Lets get the options... refresh_type = "Normal" try: refresh_type = json_data['refresh_type'] except: print("Not given a refresh type, using the normal default type") # Lets check how old the datapoint is. Older than the normal value will result in a refresh refresh_time = default_refresh_time if refresh_type == "Normal": refresh_time = default_refresh_time elif refresh_type == "Force": refresh_time = 0 elif refresh_type == "Cache": refresh_time = 99999 # We have our refresh time, lets get the location and its update time... mydb = init_mysql("db_character") cursor = mydb.cursor() location_get = "SELECT * FROM tb_character_location WHERE character_id = %s" cursor.execute(location_get, (json_data['character_id'], )) result_raw = cursor.fetchall() ### Wait a second... ### Did this character ever get generated their location? ### If not, we need to generate it first... if len(result_raw) <= 0: print("Missing data for this character, generating the information...") result_raw = update_character_location( json_data['character_id'], json_data['character_auth_code']) result = get_format_from_raw_full(result_raw, cursor)[0] # Removing update time result['update_time'] = "" if len(result['wormhole_data']) > 0: result['wormhole_data'] = json.loads(result['wormhole_data']) else: result['wormhole_data'] = "{}" print(result) ### Getting the actual information we need data system_info = get_system_info(result['character_system_id']) result['data'] = system_info return throw_json_success("success", result) else: result = get_format_from_raw(result_raw, cursor) update_time = result['update_time'] time_between = datetime.now() - update_time minutes = time_between.seconds / 60 / 60 if (minutes < refresh_time): print("Refreshing our location information...") update_character_location(json_data['character_id'], json_data['character_auth_code']) location_get = "SELECT * FROM tb_character_location WHERE character_id = %s" cursor.execute(location_get, (json_data['character_id'], )) result_raw = cursor.fetchall() result = get_format_from_raw_full(result_raw, cursor)[0] print(result) # Removing update time result['update_time'] = "" if len(result['wormhole_data']) > 0: result['wormhole_data'] = json.loads(result['wormhole_data']) else: result['wormhole_data'] = "{}" # Giving the result the location-based data that we are SUPPOSED to have... ### Getting the actual information we need data system_info = get_system_info(result['character_system_id']) result['data'] = system_info return throw_json_success("success", result)
def update_character_location(character_id, character_auth_code): print("Updating the location data for the given character") ### Data we are collecting solar_system_id = "" solar_system_name = "" docked = True structure_id = 0 structure_name = "Unknown" ship_name = "" ship_custom_name = "" ship_id = "" # Given the character ID and character auth code, lets get (or generate) and access token sso_id = auth_character(character_id, character_auth_code) # Checking for error if sso_id == -1: return throw_json_error(500, "Invalid character authentication code") # Otherwise, lets get that token access_token = get_access_token(character_id, sso_id) # Now that we have an access token, lets begin working with it # First we will get the players exact location result_location = api_call_get( "characters/" + str(character_id) + "/location/", { "character_id": character_id, "token": access_token }) # Getting the solar system ID and the structure ID result_location_content = json.loads( result_location.content.decode('utf-8')) try: solar_system_id = result_location_content['solar_system_id'] except KeyError as err: solar_system_id = 30000142 try: structure_id = result_location_content['structure_id'] except KeyError as err: docked = False # Next, we will get the players ship result_ship = api_call_get("characters/" + str(character_id) + "/ship/", { "character_id": character_id, "token": access_token }) result_location_ship = json.loads(result_ship.content.decode('utf-8')) print(result_location_ship) ship_custom_name = result_location_ship['ship_name'] ship_id = result_location_ship['ship_type_id'] ### Getting static data solar_system_name = get_solar_system_name_from_id( solar_system_id)['solarSystemName'] ship_name = get_ship_name_from_id(ship_id)['typeName'] if docked: structure_name = get_station_name_from_id(structure_id) if len(structure_name) <= 0: structure_name = "Unknown" # Lets check; if this is a wormhole then there is an abundance of extra information we need to know... wormhole_data = "" if solar_system_name[0:1] == "J": # Lets get the wormhole data wormhole_data = get_wormhole_data_from_id(solar_system_id, solar_system_name) wormhole_data = json.dumps(wormhole_data) ### Final data set, lets create or update our entry ### Check if we have an entry mydb = init_mysql("db_character") cursor = mydb.cursor() statement_check = "SELECT character_id FROM tb_character_location WHERE character_id = %s" cursor.execute(statement_check, (character_id, )) result_raw = cursor.fetchall() if len(result_raw) <= 0: # Time to create the entry # Creating insert data insert_data = [ wormhole_data, docked, character_id, solar_system_name, solar_system_id, structure_name, structure_id, ship_name, ship_id, ship_custom_name ] statement_insert = "INSERT INTO tb_character_location (wormhole_data, character_docked, character_id, character_system_name, character_system_id, character_structure_name, character_structure_id, character_ship_name, character_ship_id, character_ship_custom_name)" \ "VALUES" \ "(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" cursor.execute(statement_insert, insert_data) mydb.commit() else: # Update the entry statement_update = "UPDATE tb_character_location SET wormhole_data = %s, character_docked = %s, update_time = NOW(), character_system_name = %s, character_system_id = %s, character_structure_name = %s, character_structure_id = %s, character_ship_name = %s, character_ship_id = %s, character_ship_custom_name = %s WHERE character_id = %s" cursor.execute(statement_update, (wormhole_data, docked, solar_system_name, solar_system_id, structure_name, structure_id, ship_name, ship_id, ship_custom_name, character_id)) mydb.commit() # Regardless: location_get = "SELECT * FROM tb_character_location WHERE character_id = %s" cursor.execute(location_get, (character_id, )) result_raw = cursor.fetchall() return result_raw
def edit_sig(): ##print("Editing a sig and saving") # Getting the sig info json_input = request.data json_data = json.loads(json_input.decode('utf-8')) ### Authenticating the player # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Building data from the given info mydb = init_mysql("db_map") cursor = mydb.cursor() ############### ############### ## Checking for wormhole data update... ############### ############### GET_SIG = "SELECT * FROM tb_sig WHERE sig_id = %s" cursor.execute(GET_SIG, (json_data['sig_id'],)) result = get_format_from_raw_full(cursor.fetchall(), cursor)[0] ###print(result) existing_wormhole_data = json.loads(result['sig_wormhole_data']) input_wormhole_data = json.loads(json_data['sig_wormhole_data']) ###print(existing_wormhole_data) ###print(input_wormhole_data) set_age = result['sig_age'] ### If we are setting the type and there WAS NOT A TYPE BEFORE, we NEED to update the age! if ("wormhole_type" not in existing_wormhole_data and "wormhole_type" in input_wormhole_data) or not (existing_wormhole_data['wormhole_type'] == input_wormhole_data['wormhole_type']): ### Okay time to get the age for this wormhole type... ### Note: If we are given nothing we want to set the age BACK to zero new_wormhole_type = input_wormhole_data['wormhole_type'] if len(new_wormhole_type) <= 0: set_age = 0 else: ### Okay, we've been given a NEW input... ### Lets get that age... set_age = 1440 scan_strength = result['sig_scan_strength'] insert = "UPDATE tb_sig SET sig_mass = %s, sig_display_lifespan = %s, sig_id_num = %s, sig_id_letter = %s, sig_type = %s, sig_name = %s, sig_wormhole_data = %s, sig_age = %s, sig_scan_strength = %s WHERE sig_id = %s" data = [json_data['sig_mass'], json_data['sig_display_lifespan'], json_data['sig_id_num'], json_data['sig_id_letter'], json_data['sig_type'], json_data['sig_name'], str(json_data['sig_wormhole_data']), set_age, scan_strength, json_data['sig_id']] ##print("EXECUTING...") cursor.execute(insert, data) mydb.commit()