-
-
Save habnabit/5617083 to your computer and use it in GitHub Desktop.
This file contains 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 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