sql_gps_by_vin.py
1.33 KB
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
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
# -*- coding:utf-8 -*-
import re
import datetime
import logging
from dateutil.relativedelta import relativedelta
import numpy as np
import pandas as pd
import pymysql
#从业务提供的表中导出对应的设备号
#线上
db_conn_gps = pymysql.Connect(host='192.168.5.22', port=3307, user='user_chenqj',
passwd='MtWSIfaf', db='gps', charset='utf8')
def selectSnbyVin(vinList):
print(f"{len(vinList)}")
vinListStr = "','".join(vinList)
sql = f"SELECT dti.sn,dv.standno FROM d_vehicle dv LEFT JOIN d_track_info dti ON dv.vehicleId = dti.trackerId WHERE dti.sn IS NOT NULL AND dv.standno IN ('{vinListStr}')"
cursor = db_conn_gps.cursor()
cursor.execute(sql)
result = cursor.fetchall()
df = pd.DataFrame(list(result),columns=('sn','vin'))
return df
if __name__ == '__main__':
df = pd.read_excel("2018~2019可清除的车架号.xlsx")
print(df.columns)
df['vin'] = df['vin'].astype(str)
vinList = list(df['vin'])
total = len(vinList)
sumCount = int(total/10000)
sn_df = selectSnbyVin(vinList[0:10000])
for n in range(sumCount):
startRow = (n+1)*10000
endRow = (n+2)*10000
sn_df_tmp = selectSnbyVin(vinList[startRow:endRow])
sn_df = sn_df.append(sn_df_tmp)
sn_df.to_excel("2018~2019可清除的sn.xlsx",index=False)