Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- '''
- COPYRIGHT:
- (C) 2017 Victor Pino <victopin0@gmail.com>
- LICENCIA: GPL3
- '''
- import psycopg2
- import os
- from config_base import CSV_UPLOAD
- conn = psycopg2.connect(database='georeferenciacion',user='geoserver',password='11', host='localhost')
- cursor = conn.cursor()
- try:
- for csv_file in os.listdir(CSV_UPLOAD):
- path_csv = CSV_UPLOAD + "/" + csv_file
- query = "COPY georeferencia FROM STDIN DELIMITER ',' CSV"
- with open(path_csv) as f:
- cursor.copy_expert(query, f)
- if os.path.exists(path_csv):
- os.remove(path_csv)
- conn.commit()
- except Exception, ex:
- print ex.__class__
- print ex
- finally:
- conn.close()
Add Comment
Please, Sign In to add comment