jweinst1
11/3/2015 - 7:14 AM

db func.py

db func.py

import json

def retrieve_json(name):
	with open(name) as dj:
		data = json.load(dj)
		return data
		
def add_data(name, key, value):
	try:
		book = retrieve_json(name)
		book[key] = value
		dj = open(name, 'w')
		dj.write(json.dumps(book))
		dj.close()
		return 'data saved'
	except:
		return 'data not saved'
		
def get_data(name, key):
	d = retrieve_json(name)
	return d[key]
		
#functions for accessing json data in python