def copy_db_to_csv(dsn, path, scrub_pii=False):
if "<STR_LIT>" in dsn or "<STR_LIT>" in dsn:<EOL><INDENT>conn = psycopg2.connect(dsn=dsn)<EOL><DEDENT>else:<EOL><INDENT>conn = psycopg2.connect(database=dsn, user="<STR_LIT>")<EOL><DEDENT>cur = conn.cursor()<EOL>for table in table_names:<EOL><INDENT>csv_path = os.path.join(path, "<STR_LIT>".format(table))<EOL>with open(csv_path, "<STR_LIT:w>") as f:<EOL><INDENT>sql = "<STR_LIT>".format(table)<EOL>cur.copy_expert(sql, f)<EOL><DEDENT><DEDENT>conn.close()<EOL>if scrub_pii:<EOL><INDENT>_scrub_participant_table(path)<EOL><DEDENT>
Copy a local database to a set of CSV files.