Skip to content

Instantly share code, notes, and snippets.

@hoosteeno
Last active December 24, 2015 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoosteeno/6781738 to your computer and use it in GitHub Desktop.
Save hoosteeno/6781738 to your computer and use it in GitHub Desktop.
Python script for creating sql from healthy dialog spreadsheet.
#!/usr/bin/python
"""
* There is no need to run this per location; you can concatenate all input files or all output files.
* Modify line 15 with input filename
* Direct stdout to output filename (a .sql file)
* Work with DBAs (oncall if necessary) to get this done: https://bugzilla.mozilla.org/show_bug.cgi?id=922340
Example output:
UPDATE profile, auth_user SET profile.dialog = '14,7,36' WHERE profile.user_id = auth_user.id AND auth_user.username = 'foo';
"""
lines = []
with open("santaclara_dialog_20131030.csv", "rU") as f:
lines = f.readlines()
for line in lines:
a = line.rstrip().split(',')
username = a[0]
dialog = ','.join(a[1:]).strip('"')
print ("UPDATE profile, auth_user SET profile.dialog = '%s' "
"WHERE profile.user_id = auth_user.id "
"AND auth_user.username = '%s';" % (dialog, username))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment