linbeistation/import_points.py

37 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
import csv
import uuid
import os
import psycopg2
import codecs
from pip._vendor import chardet
# G1 = 'host=210.77.68.250 port=5432 dbname=g214_test user=g214 password=g214G214'
G2 = 'host=210.77.68.250 port=5432 dbname=linbei user=linbei password=g214G214'
def insert_specimen(sn,point_lon,point_lat,x,y):
with psycopg2.connect(G2) as connection:
with connection.cursor() as cursor:
id = uuid.uuid4()
print(id)
cursor.execute(
'insert into dashboard_points (id,sn,point_lon,point_lat,x,y,created,updated) values (%s,%s, %s, %s, %s,%s,now(),now())', (str(id),sn,point_lon,point_lat,x,y) )
connection.commit()
return id
if __name__ == '__main__':
with open('D:/2019/linbei/BaseStation_C_ALL.csv', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
i = []
for r in reader:
sn = r[0]
point_lon = r[1]
point_lat = r[2]
x = r[3]
y = r[4]
print(r)
insert_specimen(sn,point_lon,point_lat,x,y)