json - Why do I get a Parse error? (Python) -


i getting parse error >> parseerror: not well-formed (invalid token): line 1, column 1.
need parse json file kml file!
please keep note not of code!

if me right there did wrong?
getting error (valueerror: time data "'2013-07-26t22:34:56z'" not match format '%y-%m-%dt%h:%m:%sz') when changing "s" "r" right after %(timestampms) in code:

"<timestamp><when>%(timestampms)s</when></timestamp>"   

this content of json file (just few) ignore "kind" type:

{   "data" :{     "items" :[{       "kind" : "latitude#location",       "timestampms" : "1374870896803",       "latitude" : 34.9482949,       "longitude" : -85.3245474,       "accuracy" : 2149     }]   } } 

this traceback:

traceback (most recent call last):   file "..\mapplot.py", line 106, in <module>   drawmapdata(getkmlfiles(),imagedata[0], "location history.png",    imagedata[1], imagedata[2], imagedata[3],    imagedata[4],imagedata[5],imagedata[6])   file "..\mapplot.py", line 21, in getkmlfiles   kmldata.append(readkmlfile(dirname, filename))   file "..\mapplot.py", line 38, in readkmlfile   latlist.append(float(et.fromstring(line)[0].text.split(',')[0]))   file "c:\python27\lib\xml\etree\elementtree.py", line 1300, in xml   parser.feed(text)   file "c:\python27\lib\xml\etree\elementtree.py", line 1642, in feed   self._raiseerror(v)   file "c:\python27\lib\xml\etree\elementtree.py", line 1506, in _raiseerror   raise err 

here code parsing json kml:

import json import os, time, math datetime import datetime time import mktime import xml.etree.elementtree et pil import image, imagedraw   def parse_json_data_to_kml_file():    kml_file = open('location.kml', "w")    json_file = open('locationhistory.json')   json_string = json_file.read()   json_data = json.loads(json_string)    locations = json_data["data"]["items"]    placemark = ["<placemark>",                "<timestamp><when>%(timestampms)s</when></timestamp>",                "<extendeddata>",                "<data name=\"accuracy\">",                "<value>%(accuracy)r</value>]",                "</data>",                "</extendeddata><point><coordinates>%(longitude)r, %                (latitude)r</coordinates></point>",                "</placemark>"]                 placemark = "\n".join(placemark)     location in locations:        location['timestampms'] =         datetime.fromtimestamp(int(location.get("timestampms"))/1000)        .strftime("%y-%m-%dt%h:%m:%sz")         temp = placemark % location        kml_file.write("\n" + temp + "\n")      kml_file.close()    json_file.close()  parse_json_data_to_kml_file() 


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -