Skip to content

Instantly share code, notes, and snippets.

@habnabit
Forked from cluelesscoder/gist:5616667
Last active December 17, 2015 13:29
Show Gist options
  • Save habnabit/5617083 to your computer and use it in GitHub Desktop.
Save habnabit/5617083 to your computer and use it in GitHub Desktop.
import sqlite3
from collections import defaultdict
DATABASE = 'C:/Misc/myscripts/workprototype/workprototype.db'
conn = sqlite3.connect(database=DATABASE)
curs = conn.cursor()
prod_dict = {}
curs.execute('select name, desc from companies')
for name, desc in curs:
prod_dict[name] = {'products': [], 'description': desc}
curs.execute(
'select c.name, p.name, p.desc '
'from companies c '
'inner join products p using (co_id)')
for co_name, prod_name, prod_desc in curs:
prod_dict[co_name]['products'].append(
{'name': prod_name, 'description': prod_desc})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment