Created
June 25, 2015 21:30
-
-
Save siennathesane/bc3918c0328057bdcc71 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
from sqlalchemy import create_engine, MetaData, Table, select, func | |
engine = create_engine('postgresql+psycopg2://postgres:postgres@localhost:5432/cm', convert_unicode=True) | |
metadata = MetaData(bind=engine) | |
db = engine.connect() | |
hosts = Table('hosts', metadata, autoload=True) | |
results = db.execute(select({hosts})) | |
json_results = json.dumps([dict(r) for r in results]) | |
results = db.execute(select({hosts})) | |
hosts_list =[] | |
for x in results: | |
hosts_list.append(x[hosts.c.host_name]) | |
hosts_dict = dict.fromkeys(hosts_list) | |
for key, value in hosts_dict.items(): | |
hosts_dict[key] = { | |
{column : value for column,value in x.items()} | |
for x in results} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment