Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
insert_station_info.py 1.17 KB
Copy Edit Raw Blame History
liuyueming authored 2021-12-29 17:54 . 提交所有代码
from toolbox import BaiduMap
from config import *
baidu_api = BaiduMap(BD_AK)
import pymysql
def insert_station_info():
db = pymysql.connect(host=HOST, user=USER, passwd=PASSWORD, db=DB, charset=CHARSET)
cursor = db.cursor()
# 查找数据库,如果station重复则保留一个结果
station_number = cursor.execute('select * from data group by station having count(station)>1')
# 所有查询结果
station_result = cursor.fetchall()
# 遍历所有结果,然后把数据插入info表,其中字段station_id name latitude longitude从原始表data取值不修改
# 字段country province city district分别代表国家,省份,城市,县或区级信息是通过传递经纬度调用百度api取到的
for i in station_result:
#print(baidu_api.get_location(i[2],i[3]))
sql = 'insert into info values(%s, %s, %s, %s, %s, %s, %s, %s)'
values = [i[0],i[5],i[2],i[3],baidu_api.get_location(i[2],i[3])['country'],baidu_api.get_location(i[2],i[3])['province'],baidu_api.get_location(i[2],i[3])['city'],baidu_api.get_location(i[2],i[3])['district']]
print(values)
cursor.execute(sql,values)
db.commit()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化