drought_backup/import/importland.py

36 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
import csv
import uuid
import os
import psycopg2
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=drought user=drought password=g214G214'
def insert_administrative(name, cultivated_land_area, irrigated_land, eatch_land, eatch_Irrigated_land):
with psycopg2.connect(G2) as connection:
with connection.cursor() as cursor:
id = uuid.uuid4()
cursor.execute(
'insert into dashboard_landuse(id, name ,date,cultivated_land_area, irrigated_land, eatch_land,eatch_Irrigated_land,added, updated) values (%s, %s, 2016, %s, %s, %s, %s,now(),now() )',
(str(id), name, cultivated_land_area, irrigated_land, eatch_land, eatch_Irrigated_land))
connection.commit()
return id
if __name__ == '__main__':
with open('D:/2018/02.csv') as csvfile:
reader = csv.reader(csvfile)
i = 0
for r in reader:
name = r[0]
cultivated_land_area = r[1]
irrigated_land = r[2]
eatch_land = r[3]
eatch_Irrigated_land = r[4]
print(r[0])
insert_administrative(name, cultivated_land_area, irrigated_land, eatch_land, eatch_Irrigated_land)