伊春新闻网 > 伊春旅游 >

余杭区划分为两个区

时间:2020-09-11 11:20 来源:未知  手机版

画册欣赏,昆仑山舰,080012

def __init__(self): self.name = ['北京市', '上海市', "天津市", "重庆市", "黑龙江省", "吉林省", "辽宁省", "内蒙古自治区", "河北省", "山西省", "陕西省", "山东省", "新疆维吾尔自治区", "青海省", "甘肃省", "宁夏回族自治区", "河南省", "江苏省", "湖北省", "浙江省", "安徽省", "福建省", "江西省", "湖南省", "贵州省", "四川省", "广东省", "云南省", "广西壮族自治区", "海南省", "台湾", "西藏自治区", "香港", "澳门"] self.url = "https://restapi.amap.com/v3/config/district?keywords={}" self.params = { 'subdistrict': '2', # 表示获取下两级行政区域(省/市/区) 'key': '高德注册应用的key', self.db = pymysql.connect(host='localhost', user='用户', password='密码', database='数据库', charset='utf8') # 连接数据库 self.cur = self.db.cursor() # 创建游标 def save_2_mysql(self, tradename, id): ‘’‘保存到数据库’‘’ insert_sql = 'insert into citys (name, parent_id) values (%s, %s)' self.cur.execute(insert_sql, [tradename, id]) self.db.commit() def district(self): ‘’‘获取每个省的下两级行政区域数据’‘’ districts = [] for name in self.name: response = requests.get(self.url.format(name), params=self.params) datas = json.loads(response.text) if datas['status'] == '1': for data in datas['districts']: province = {} province['name'] = data['name'] # 名称 province['code'] = data['adcode'] # 区域编码 province['districts'] = [] self.save_2_mysql(province['name'], 0) for every in data['districts']: city = {} city['name'] = every['name'] city['code'] = every['adcode'] city['districts'] = [] self.save_2_mysql(city['name'], 1) for i in every['districts']: district = {} district['name'] = i['name'] district['code'] = i['adcode'] city['districts'].append(district) self.save_2_mysql(district['name'], 2) province['districts'].append(city) districts.append(province) # 构建json格式的数据 with open('gaodecitys.json', 'w') as f: f.write(json.dumps(districts)) # 保存json数据 self.cur.close() self.db.close() # 关闭数据库连接

本站所有文章均来自搜索引擎和其他站点公开内容,如有侵权或表述不当,请联系并标明身份和情况后立即删除。
本文地址: http://www.0458zhaopin.com/yichunlvyou/32447.html

本文标签:行政区域 数据 宁夏回族自治区 西藏自治区 新疆维吾尔自治区

相关文章

热图 更多>>
热门文章 更多>>