desertvegetationcommunitysu.../import_specieslibrary.py

47 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
import csv
import re
import uuid
import os
import psycopg2
import xlrd
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=communityDB_test user=community password=community!@#'
def insert_lib(family,familylatinname,scientificchinesename,l):
with psycopg2.connect(G2) as connection:
with connection.cursor() as cursor:
id = uuid.uuid4()
cursor.execute(
'insert into dashboard_specieslibrary(id,family,familylatinname,scientificchinesename,latinname) values (%s,%s, %s,%s,%s)'
, (str(id),family,familylatinname,scientificchinesename,l))
connection.commit()
return id
if __name__ == '__main__':
l = None
workbook = xlrd.open_workbook('D:/2020/荒漠植被调查/植物志.xlsx')
table = workbook.sheets()[0]
for row in range(table.nrows):
v = table.row_values(row)[0]
if v != '':
print(table.row_values(row)[0])
family = table.row_values(row)[0]
familylatinname = table.row_values(row)[1]
scientificchinesename = table.row_values(row)[2]
latinname = table.row_values(row)[3]
if 'var' in str(latinname):
l = str(latinname).split(' ')[0]+' '+str(latinname).split(' ')[1]+' '+ '(var)'
else:
l = str(latinname).split(' ')[0]+' '+str(latinname).split(' ')[1]
insert_lib(family,familylatinname,scientificchinesename,l)