-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathez_region.py
More file actions
31 lines (24 loc) · 805 Bytes
/
ez_region.py
File metadata and controls
31 lines (24 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __file__: ez_region
import requests
import json
import pymongo
def download_region():
"""
简易的天地图行政区下载
:return: null
"""
client = pymongo.MongoClient(host='localhost', port=27017)
db = client.lvyou
collection = db.tianditu_zhongguo_region
r = requests.get(
'http://api.tianditu.gov.cn/administrative?postStr={"searchWord":"中国","searchType":"1","needSubInfo":"true","needAll":"true","needPolygon":"true","needPre":"true"}&tk=a4ee5c551598a1889adfabff55a5fc27')
data = json.loads(r.text)
data = data['data']
for item in data:
child_list = item['child']
for chi in child_list:
collection.insert(chi)
if __name__ == '__main__':
download_region()