Skip to content

Instantly share code, notes, and snippets.

@munro

munro/stocks.py Secret

Created July 21, 2016 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save munro/3686e3b060c2cd7959350ea8bf77ff2c to your computer and use it in GitHub Desktop.
Save munro/3686e3b060c2cd7959350ea8bf77ff2c to your computer and use it in GitHub Desktop.
from datetime import datetime, timedelta
from sqlalchemy import Column, DateTime, Integer, MetaData, Numeric, Table, select
meta = MetaData()
def stock_table(company):
return Table(
'stock_{}'.format(company),
meta,
Column('id', Integer),
Column('volume', Integer),
Column('price', Numeric),
Column('date', DateTime)
)
aapl = stock_table('aapl')
engine.execute(
select(['*'])
.select_from(aapl)
.where(aapl.c.date >= datetime.now() - timedelta(days=7))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment