#!/usr/bin/python3 import cgi, shelve, json, os, os.path from PersistentDict import PersistentDict form = cgi.FieldStorage() session = form.getfirst('session') shelfFileName = 'sessions/shelf.' + session print("Content-type: application/json\n\n") if os.path.exists(shelfFileName): try: #shelf = shelve.open(shelfFileName, 'r') #shelf = shelve.Shelf(PersistentDict(shelfFileName, 'r')) shelf = PersistentDict(shelfFileName, 'r') if ('redirect' in shelf['data']): status = {} status['status'] = '' status['redirect'] = True print(json.dumps(status)) else: print(json.dumps(shelf['data'])) removeShelf = ('done' in shelf['data'] and shelf['data']['done']) shelf.close() if removeShelf: os.remove(shelfFileName) except Exception as e: status = {} status['status'] = "Caught exception in getiTunesStatus: " + str(e) status['done'] = False print(json.dumps(status)) else: print('{"status": "Invalid session - try again.", "done": true}')