Guest User

Untitled

a guest
Oct 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import csv
  2. from postgres import Postgres
  3.  
  4. POSTGRES_URL = "REDACTED"
  5.  
  6. db = Postgres(POSTGRES_URL)
  7.  
  8. keymap = {
  9. 'Key': 0,
  10. 'Name': 1,
  11. 'Latitude': 2,
  12. 'Longitude': 3,
  13. 'Street Address': 4,
  14. 'City': 5,
  15. 'State': 6,
  16. 'Zip': 7,
  17. 'Type': 8,
  18. 'Phone': 9,
  19. 'Website': 10
  20. }
  21. with open('LocationData.csv', 'rb') as f:
  22. reader = csv.reader(f, delimiter=',', quoting=csv.QUOTE_NONE)
  23. count = 0
  24. for row in reader:
  25. if count == 0:
  26. count += 1
  27. continue
  28. db.run("INSERT INTO locations (name, type, latitude, longitude, address, phone) VALUES ('{}','{}','{}','{}','{}','{}');".format(row[keymap['Name']], row[keymap['Type']], row[keymap['Latitude']], row[keymap['Longitude']], row[keymap['Street Address']], row[keymap['Phone']]))
  29.  
  30. count += 1
Add Comment
Please, Sign In to add comment