Today completed the provincial cities and counties as well as the completion of the administrative units under the project number project query by high moral map api, here are some of the problems encountered:
Some projects completed in Unit 1 on the high moral map is finding out ,,, is not finding out, the display will not be verified. Api is by finding out relevant information ,,,, this is a bit uncomfortable.
2 high moral map to the quota ordinary developers are limited because of a little time to try to write code and more, in the end did not check all finished.
The following is a project code, I wrote a little python beginner trash
! # / usr / bin / Python # - * - Coding: UTF . 8 - * - Import the codecs Import Requests List = [] AK = '' # extracts an item name DEF diqu (): F = codecs.open ( ' diqu. txt ' , MODE = ' R & lt ' , encoding = ' UTF-. 8 ' ) # open txt file to' UTF- . 8 'code reader line = f.readline () # line form reading document the while line: A = line.split () B = A [ 0: 1 ] # This is selected to be read digits list.append (b) # to add it in the list of 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 = the 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)
This is part of the query to the data capture