Skip to content
This repository has been archived by the owner on Mar 3, 2018. It is now read-only.

Commit

Permalink
added SQL model and __main__ function utility script for uploading in…
Browse files Browse the repository at this point in the history
…fo to a SQL database
  • Loading branch information
Lyla-Fischer committed May 8, 2017
1 parent 8b06e67 commit 83bdf7c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15,668 deletions.
53 changes: 53 additions & 0 deletions mapofinnovation/model/innovation_space.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

import sqlalchemy
import psycopg2
from sqlalchemy import Column, Integer, String, Float
from sqlalchemy_utils import EmailType

class Innovation_Space(Base):
__tablename__ = "innovation_space"

primary_id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String)
email = Column(String)
aliases = Column(String)
street_address = Column(String)
city = Column(String)
state = Column(String)
country = Column(String)
latitude = Column(Float, nullable=True)
longitude = Column(Float, nullable=True)
phone = Column(String)

def __repr__(self):
return "<Innvation_Space(name: %r at street_address: %r and email: %r)>" \
% (self.name, self.street_address, self.email)

if __name__ == "__main__":
#If run as main, reset the engine
engine = sqlalchemy.create_engine("postgres://lyla@/atlas")
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)

from sqlalchemy.orm import Session
import csv
session = Session(bind=engine)

with open('most_up-to-date_spaces.csv') as csvfile:
reader = csv.DictReader(csvfile)
spaces = [Innovation_Space(name = row['name'],
email = row['email'],
aliases = row['aliases'],
street_address = row['street_address'],
city = row['city'],
state = row['state'],
country = row['country'],
latitude = row['latitude'],
longitude = row['longitude'],
phone = row['phone']) for row in reader]

# print(spaces)
session.add_all(spaces)
session.commit()
1 change: 0 additions & 1 deletion mapofinnovation/public/new_tools_and_social.csv

This file was deleted.

Loading

0 comments on commit 83bdf7c

Please sign in to comment.