def request(text): """Make a request to the database's HTTP server""" tutor_find_db.open_db() response = tutor_find_db.handle_request(json.dumps(text)) tutor_find_db.close_db() try: return json.loads(response) except ValueError: print response raise
def request(text): """Make a request to the database's HTTP server""" response = None if direct_requests: tutor_find_db.open_db() response = tutor_find_db.handle_request(json.dumps(text)) tutor_find_db.close_db() else: conn = httplib.HTTPConnection('localhost:8000') conn.request('POST', '/tutor_find_db', json.dumps(text), { 'Content-Type': 'application/json', 'Accept': 'application/json', }) response = conn.getresponse().read() conn.close() try: return json.loads(response) except ValueError: print response raise
def set_preferred(user, preferred): tutor_find_db.open_db() tutor_find_db.set_preferred(user['user_id'], preferred) tutor_find_db.close_db()