41 lines
1.7 KiB
Python
41 lines
1.7 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,inhabitant, households, registered_population, man,women,natality,fatalities,population_growth,demographic_urbanization):
|
|
with psycopg2.connect(G2) as connection:
|
|
with connection.cursor() as cursor:
|
|
id = uuid.uuid4()
|
|
cursor.execute(
|
|
'insert into dashboard_population (id,name,date,inhabitant, households, registered_population, man,women,natality,fatalities,population_growth,demographic_urbanization,added,updated) values (%s, %s, 2016, %s, %s, %s, %s, %s, %s, %s, %s, %s,now(),now() )',
|
|
(str(id), name,inhabitant, households, registered_population, man,women,natality,fatalities,population_growth,demographic_urbanization))
|
|
connection.commit()
|
|
return id
|
|
|
|
|
|
if __name__ == '__main__':
|
|
with open('D:/2018/04.csv') as csvfile:
|
|
reader = csv.reader(csvfile)
|
|
i = 0
|
|
for r in reader:
|
|
name = r[0]
|
|
inhabitant = r[1]
|
|
households = r[2]
|
|
registered_population = r[3]
|
|
man = r[4]
|
|
women = r[5]
|
|
natality = r[6]
|
|
fatalities = r[7]
|
|
population_growth = r[8]
|
|
demographic_urbanization = r[9]
|
|
print(r)
|
|
insert_administrative(name,inhabitant, households, registered_population, man,women,natality,fatalities,population_growth,demographic_urbanization)
|