Guest User

Untitled

a guest
Mar 17th, 2017
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. '''
  4. COPYRIGHT:
  5.  (C) 2017 Victor Pino <victopin0@gmail.com>
  6. LICENCIA: GPL3
  7. '''
  8.  
  9. import psycopg2
  10. import os
  11. from config_base import CSV_UPLOAD
  12.  
  13. conn = psycopg2.connect(database='georeferenciacion',user='geoserver',password='11', host='localhost')
  14.  
  15. cursor = conn.cursor()
  16.  
  17. try:
  18.  
  19.     for csv_file in os.listdir(CSV_UPLOAD):
  20.  
  21.         path_csv = CSV_UPLOAD + "/" + csv_file
  22.    
  23.         query = "COPY georeferencia FROM STDIN DELIMITER ',' CSV"
  24.  
  25.         with open(path_csv) as f:
  26.  
  27.             cursor.copy_expert(query, f)
  28.  
  29.         if os.path.exists(path_csv):
  30.             os.remove(path_csv)
  31.  
  32.     conn.commit()
  33.  
  34. except Exception, ex:
  35.  
  36.     print ex.__class__
  37.     print ex
  38.  
  39. finally:
  40.  
  41.     conn.close()
Add Comment
Please, Sign In to add comment