Skip to content

Instantly share code, notes, and snippets.

@eleddy
Created January 18, 2013 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eleddy/4569395 to your computer and use it in GitHub Desktop.
Save eleddy/4569395 to your computer and use it in GitHub Desktop.
"""
Tutorial at http://docs.sqlalchemy.org/en/rel_0_8/orm/tutorial.html
Data at http://pastie.org/5659260
Key Points:
- requires: sqlalchemy, psycopg2
- Setting up new database and user
- Difference between sql, postgres, sqlite
- Sqlite and timezones
- Connecting to the DB and DSNs
- Postegres, templates, unicode issues
- Adding and retrieving data
- install postgres
"""
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
import urllib2
import csv
#engine = create_engine('postgresql://localhost/pyclass1', echo=True)
#Base = declarative_base()
#Base.metadata.create_all(engine)
#Session = sessionmaker(bind=engine)
#class TaxReturns(Base):
# __tablename__ = 'movies'
def add_stuff():
pass
def get_stuff():
pass
def get_csv():
"""
Get csv from the file system and make a list/dictionary
... whatever makes sense
"""
field_names = ["RecordNumber","Zipcode","ZipCodeType","City","State","LocationType","Lat","Long","Xaxis","Yaxis","Zaxis","WorldRegion","Country","LocationText","Location","Decommisioned","TaxReturnsFiled","EstimatedPopulation","TotalWages","Notes"]
with open('pastie-5659260.txt', 'rb') as csvfile:
spamreader = csv.DictReader(csvfile, fieldnames=field_names, delimiter=',', quotechar='"')
import pdb; pdb.set_trace()
for row in spamreader.values():
print spamreader.next()
if __name__ == '__main__':
get_csv()
#add_stuff()
#get_stuff()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment