Created
January 10, 2016 18:08
-
-
Save mgax/0a84bb8240bdba4c1061 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from time import time | |
import simplejson as json | |
from datetime import datetime | |
from sqlalchemy import create_engine | |
engine = create_engine( | |
'mssql+pymssql://user:pass@server:1433/portal_mj_nou?charset=utf8&timeout=300' | |
) | |
def clean(value): | |
if isinstance(value, datetime): | |
return value.isoformat() | |
if isinstance(value, str): | |
return str.decode('latin-1') | |
return value | |
def dump(conn, query): | |
result = conn.execute(query) | |
t0 = t1 = time() | |
for n, row in enumerate(result): | |
data = {k: clean(v) for k, v in row.items()} | |
print json.dumps(data) | |
t = time() | |
if t - t1 > 5: | |
print>>sys.stderr, int(t - t0), n | |
t1 = t | |
conn = engine.connect() | |
dump(engine, 'select * from %s' % sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment