项目完成进度一
今天完成了根据项目完成单位通过高德地图api进行查询项目的省市县以及行政区号,下面是遇到的几点问题:
1有些项目完成单位在高德地图上是查不到的,,,也不是查不到,会显示该地没有核实。通过api是查不到相关信息的,,,,这点有点难受。
2高德地图给普通开发者的配额数量是有限的,因为写代码时候尝试的有点多,,到最后没有全部查完。
下面的是项目代码,我是python初学者写的有点垃圾
#!/usr/bin/python # -*- coding: UTF-8 -*- import codecs import requests list = [] ak = '' # 提取项目名称 def diqu(): f = codecs.open('diqu.txt', mode='r', encoding='utf-8') # 打开txt文件,以‘utf-8’编码读取 line = f.readline() # 以行的形式进行读取文件 while line: a = line.split() b = a[0:1] # 这是选取需要读取的位数 list.append(b) # 将其添加在列表之中 line = f.readline() f.close() def address(address): url = "http://restapi.amap.com/v3/geocode/geo?key=%s&address=%s" % (ak, address) data = requests.get(url) contest = data.json() panduan = contest['count'] if panduan == "1": a = contest['geocodes'][0]['province'] b = contest['geocodes'][0]['city'] c = contest['geocodes'][0]['district'] d = contest['geocodes'][0]['adcode'] a = ''.join(a) print(a) with open('jeiguo.txt', 'a+', encoding="utf-8") as q: q.write("\n" + a) b = ''.join(b) print(b) with open('jeiguo.txt', 'a+', encoding="utf-8") as q: q.write(b) c = ''.join(c) print(c) with open('jeiguo.txt', 'a+', encoding="utf-8") as q: q.write(c) d = ''.join(d) print(d) with open('jeiguo.txt', 'a+', encoding="utf-8") as q: q.write("," + d) else: with open('jeiguo.txt', 'a+', encoding="utf-8") as q: q.write("\n" + "查询失败") if __name__ == '__main__': diqu() print(list) with open('jeiguo.txt', 'a+', encoding="utf-8") as f: f.write('diqu,xzqh') for i in list: address(i)
这是查询到的部分数据截图