老大指示让用数据库。
这里用的Python 标准库就给弄好API的SQLite。
用和上一篇里类似的方法找到poiid,从每个poiid往后找经纬度。
然后逐一写入数据库。
截取一部分源文件用来测试的时候,神奇地发现原来的数据里都是小数点后有5位的lon和lat,居然写进去一个六位的,不明觉厉了,一会儿再写一个筛选出来的看看是什么情况。
上代码
import sqlite3 as dbapi
con=dbapi.connect('poi.db')
cur=con.cursor()
cur.execute('DROP TABLE pll_table')
cur.execute('CREATE TABLE pll_table(poiid TEXT,lon REAL,lat REAL)')
#read txt file
file=open("jsontest.txt","rt")
contents=file.read()
file.close()
#place them here
poiid=[]
#find poiid between quotes behind '"poiid":'one by one
while contents.find("poiid")>0:
hwz=contents.find('"poiid":')
twz=contents.find('"',hwz+15)
thwn=contents[hwz+10:twz]
poiid=poiid+[thwn]
contents=contents[twz+2:]
poiid=set(poiid)