def locations_download(language_code, data): locations = collections.OrderedDict() gmaps = googlemaps.Client(key=config["google_maps_api_key"]) """This dictionary is used to determine languages.""" languages = { 0: "ja", 1: "en", 2: "de", 3: "fr", 4: "es", 5: "it", 6: "nl", } for keys, values in list(data.items()): location = values[7] if location is not None: if location not in locations: locations[location] = [None, None, []] locations[location][2].append(keys) for name in list(locations.keys()): if name == "": continue uni_name = name if languages[language_code] == "ja" else unidecode( name ) # If using unidecode with Japanese, it'll translate all the characters to English print(uni_name) if name not in cities: try: read = gmaps.geocode(uni_name, language=languages[language_code]) loc_name = read[0]["address_components"][0]["long_name"] if languages[language_code] == "ja": loc_name = enc(loc_name) else: loc_name = enc(unidecode(loc_name)) """Not doing anything with these.""" country = u8(0) region = u8(0) location = u16(0) zoom_factor = u32_littleendian(6) coordinates = s16(int(read[0]["geometry"]["location"]["lat"] / (360 / 65536))) + \ s16(int(read[0]["geometry"]["location"]["lng"] / (360 / 65536))) + \ country + region + location + zoom_factor except: log("There was a error downloading the location data.", "INFO") else: coordinates = binascii.unhexlify(cities[name][0] + "0000000006000000") loc_name = enc(cities[name][1]) if locations[name][0] is None: locations[name][0] = coordinates if locations[name][1] is None: locations[name][1] = loc_name return locations
def locations_download( language_code, data ): # using Google Maps API is so much better than the crap Nintendo used for say, AP news. locations = {} gmaps = googlemaps.Client(key=config["google_maps_api_key"]) languages = { # corresponds to the Wii's language codes 0: "ja", 1: "en", 2: "de", 3: "fr", 4: "es", 5: "it", 6: "nl", } for keys, values in list(data.items()): location = values[7] if location and location != "": if location not in locations: locations[location] = [None, None, []] locations[location][2].append(keys) for name in list(locations.keys()): if name == "": continue uni_name = ( name if languages[language_code] == "ja" else unidecode(name) ) # if using unidecode with Japanese, it'll translate all the characters to English print(uni_name) coordinates = None if name not in cities: try: read = gmaps.geocode(uni_name, language=languages[language_code]) loc_name = read[0]["address_components"][0]["long_name"] if languages[language_code] == "ja": loc_name = enc(loc_name) else: loc_name = enc(unidecode(loc_name)) """Not doing anything with these.""" country = u8(0) region = u8(0) location = u16(0) zoom_factor = u32_littleendian( 6 ) # Nintendo used the value of 3 for states and countries but we probably don't have any articles that are just states or countries coordinates = ( s16( int(read[0]["geometry"]["location"]["lat"] / (360 / 65536))) + s16( int(read[0]["geometry"]["location"]["lng"] / (360 / 65536))) + country + region + location + zoom_factor ) # latitude and longitude is divided by the value of 360 (degrees of a full circle) divided by the max int for a 16-bit int except Exception as e: ex = "There was a error downloading the location data - line {}: {}".format( sys.exc_info()[-1].tb_lineno, str(e)) print(ex) log(ex, "INFO") else: coordinates = binascii.unhexlify(cities[name][0] + "0000000006000000") loc_name = enc(cities[name][1]) if locations[name][0] is None and coordinates is not None: locations[name][0] = coordinates else: del locations[name] continue if locations[name][1] is None: locations[name][1] = loc_name return locations