newmediamonitoring/import_organization.py

39 lines
1.6 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=newmediaDB3 user=newmedia password=newmedia2020!@#'
def get_organizationtype_id(name,image,province,cities,district,directly,status,level_id,id_code):
with psycopg2.connect(G2) as connection:
with connection.cursor() as cursor:
id = uuid.uuid4()
cursor.execute(
"insert into dashboard_organization(id,name,image, province, cities, district, town,village,directly,status,level_id,id_code, created, updated) values (%s,%s, %s,%s,%s,%s,'','', %s,%s,%s,%s,now(),now())"
, (str(id), name,image,province,cities,district,directly,status,level_id,id_code))
connection.commit()
print(name)
if __name__ == '__main__':
with open('D:/2020/舆论监测平台/XMTJC/数据/总.csv',encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
for r in reader:
if r[1] != '单位全称':
print(r)
name = r[1]
image = 'danweimoren.jpg'
province = '甘肃省'
cities = r[10]
district = r[11]
directly = r[6]
status = 1
level_id = '69be9ef4-b7b7-4049-a86e-7083bee40f0e'
id_code = r[2]
get_organizationtype_id(name,image,province,cities,district,directly,status,level_id,id_code)