Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# -*- coding: utf-8 -*-
import sys
import json
import simplekml
class Portal:
def __init__(self, lat, lon, portal_name, portal_photo_url): = lat # latitude
self.lon = lon # longitude
self.portal_name = portal_name # Portal Name
# Photo URL
self.portal_photo_url = portal_photo_url
def get_map_child(map_array):
result = []
for map_data in map_array:
return result
def get_portal_arr(map_name_arr, obj):
result = []
for map_name in map_name_arr:
for entity in obj['result']['map'][map_name]['gameEntities']:
# get portal entities
if entity[2][0] == 'p':
# latitude
lat = float(entity[2][2] / 1000000)
# longitude
lon = float(entity[2][3] / 1000000)
# Portalk Name
portal_name = entity[2][8]
# Photo URL
portal_photo_url = entity[2][7]
# Once stored in an array
Portal(lat, lon, portal_name, portal_photo_url))
return result
def output_kml_file(sorted_portal_arr, output_kml_file_name):
kml = simplekml.Kml()
for portal in sorted_portal_arr:
# setting photo information for google mymap
extendeddata = simplekml.ExtendedData()
extendeddata.newdata('gx_media_links', portal.portal_photo_url)
# output kml
def main():
args = sys.argv
if args[1] is None:
input_json_file_name = args[1] + '.json' # input file name
output_kml_file_name = args[1] + '.kml' # output file name
with open(input_json_file_name, 'r') as f:
for line in f:
# read file(maybe 1 line)
obj = json.loads(line)
# get child entity name
map_name_arr = get_map_child(obj['result']['map'])
# get portal array
portal_arr = get_portal_arr(map_name_arr, obj)
# sort(latitude descending)
sorted_portal_arr = sorted(
portal_arr, key=lambda h:, reverse=True)
# output
output_kml_file(sorted_portal_arr, output_kml_file_name)
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.