Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- from postgres import Postgres
- POSTGRES_URL = "REDACTED"
- db = Postgres(POSTGRES_URL)
- keymap = {
- 'Key': 0,
- 'Name': 1,
- 'Latitude': 2,
- 'Longitude': 3,
- 'Street Address': 4,
- 'City': 5,
- 'State': 6,
- 'Zip': 7,
- 'Type': 8,
- 'Phone': 9,
- 'Website': 10
- }
- with open('LocationData.csv', 'rb') as f:
- reader = csv.reader(f, delimiter=',', quoting=csv.QUOTE_NONE)
- count = 0
- for row in reader:
- if count == 0:
- count += 1
- continue
- 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']]))
- count += 1
Add Comment
Please, Sign In to add comment