Created
May 13, 2014 18:43
-
-
Save SimplyAhmazing/f88bf69e4e10f07c0eb9 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 datetime | |
import simplejson as json | |
import subprocess | |
def setClipboardData(data): | |
p = subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE) | |
p.stdin.write(data.encode('utf-8')) | |
p.stdin.close() | |
retcode = p.wait() | |
def getClipboardData(): | |
p = subprocess.Popen(['pbpaste'], stdout=subprocess.PIPE) | |
retcode = p.wait() | |
data = p.stdout.read() | |
return data.decode() | |
def saveDumpData(filename): | |
with open(filename, 'w') as f: | |
p = subprocess.Popen(['./manage.py', 'dumpdata'], stdout=f) | |
p.wait() | |
data = "" | |
with open(filename) as f: | |
data = f.read() | |
# Remove the garbage after the last ']' | |
data = data[:data.rfind(']')+1] | |
# Format pretty | |
data_dict = json.loads(data) | |
data = json.dumps(data_dict, indent=2) | |
# rewrite the file. | |
with open(filename, 'w') as f: | |
f.write(data) | |
def run(): | |
filename = 'db/fixtures/fixture ({}).json'.format( | |
datetime.datetime.now().strftime("%a %b %d, %I:%M:%S %p") | |
) | |
saveDumpData(filename) | |
if __name__ == '__main__': | |
filename = '/Users/BLAH/Projects/tmp/dumpdata.json' | |
saveDumpData(filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment