def post(self): messageid = self.request.get("messageid") if messageid == "": rawCharacter = cgi.escape(self.request.get("character"), quote = True) rawLocation = cgi.escape(self.request.get("address"), quote = True) # Validate character (character, charError) = map.validateCharacter(rawCharacter) # Validate location location = map.validateLocation(rawLocation) error, msgError = "", "" # Check validation errors and format error message if character == None: msgChar = rawCharacter else: msgChar = str(character.name) if charError != "": error = charError msgError = error if location.status != "OK": error = (error + " " + location.status.encode('utf_8')).decode('utf_8') msgError = error if (charError == "") and (location.status == "OK"): error = ("Move %s to %s. Got it!" % (msgChar, location.address.encode('utf_8'))).decode('utf_8') msgError = "" print datetime.datetime.utcnow() print "error: " + error.encode('utf_8') print type(error) print "msgError: " + msgError.encode('utf_8') print type(msgError) # Store in Message store if recordMessage("WebForm", None, self.request.remote_addr, msgChar, location, rawCharacter+" "+rawLocation, msgError): print "IN APP:" top_msgs(True) self.writeHTML(error=error, character=character, location=location) else: error = "App Error: Failed to insert message." self.writeHTML(error=error, character=character, location=location) else: # Validate messageid and get message messagekey = ndb.Key(urlsafe=messageid) message = Message() message = messagekey.get() character = Character.query(Character.name == message.character).get() location = Location() location.address = message.address location.latlng = message.latlng # If message found if not message: error = "App Error: Cannot get message." self.writeHTML(error=error, character=None, location=None) # If message not found else: # Write self.writeHTML(error="", character=character, location=location)
def kitty_pathA(): kitty_key = Character.query(Character.species == "Cat").get() kitty_pathers = KPath.query(KPath.owner == kitty_key.key).get() global post_born_opt if post_born_opt == 2: return kitty_pathers.p_2a elif post_born_opt == 3: return kitty_pathers.p_3a
def doggo_post_born(): global post_born_opt doggo_key = Character.query(Character.species == "Dog").get() doggo_post_born = PB2.query(PB2.owner == doggo_key.key).get() if born_opt == 1: return [doggo_post_born.pb_1, 1] elif born_opt == 2: return [doggo_post_born.pb_2, 2] elif born_opt == 3: return [doggo_post_born.pb_3, 3]
def panda_pathB(): global born_opt panda_key = Character.query(Character.species == "Panda").get() panda_path = Path.query(Path.owner == panda_key.key).get() if born_opt == 1: return panda_path.p_1b elif born_opt == 2: return panda_path.p_2b elif born_opt == 3: return panda_path.p_3b
def panda_post_born(): global born_opt panda_key = Character.query(Character.species == "Panda").get() panda_post_born = PB2.query(PB2.owner == panda_key.key).get() if born_opt == 1: return panda_post_born.pb_1 elif born_opt == 2: return panda_post_born.pb_2 elif born_opt == 3: return panda_post_born.pb_3
def kitty_loop(): kitty_key = Character.query(Character.species == "Cat").get() kitty_looper = Looper.query(Looper.owner == kitty_key.key).get() global post_born_opt if post_born_opt == 1: return [kitty_looper.loop_1, 1] elif post_born_opt == 2: return [kitty_looper.loop_2, 2] elif post_born_opt == 3: return [kitty_looper.loop_3, 3]
def kat_born(): kitty_key = Character.query(Character.species == "Cat").get() kitty_born = Born.query(Born.owner == kitty_key.key).get() born_opt = randrange(1, 4) if born_opt == 1: return kitty_born.born_1 elif born_opt == 2: return kitty_born.born_2 elif born_opt == 3: return kitty_born.born_3
def doggo_born(): global born_opt doggo_key = Character.query(Character.species == "Dog").get() doggo_born = Born.query(Born.owner == doggo_key.key).get() born_opt = randrange(1,4) if born_opt == 1: return doggo_born.born_1 elif born_opt == 2: return doggo_born.born_2 elif born_opt == 3: return doggo_born.born_3
def panda_born(): panda_key = Character.query(Character.species == "Panda").get() panda_born = Born.query(Born.owner == panda_key.key).get() global born_opt born_opt = randrange(1,4) if born_opt == 1: return panda_born.born_1 elif born_opt == 2: return panda_born.born_2 elif born_opt == 3: return panda_born.born_3
def kat_post_born(): global post_born_opt kitty_key = Character.query(Character.species == "Cat").get() kitty_post_born = PB2.query(PB2.owner == kitty_key.key).get() post_born_opt = randrange(1, 4) if post_born_opt == 1: return kitty_post_born.pb_1 elif post_born_opt == 2: return kitty_post_born.pb_2 elif post_born_opt == 3: return kitty_post_born.pb_3
def validateCharacter(rawCharacter): # debug: print Character table for ch in Character.query().fetch(10): print ch # Validate character formattedChar = rawCharacter.lower() character = aliases.aliases.get(formattedChar) print rawCharacter print formattedChar print "Character: %s" % character character = Character.query(Character.name == character).get() print character if character != None: error = "" print ('character found') print character else: error = "Invalid character [%s]" % rawCharacter print "error0: "+error return (character, error)
def get(self): # Loading character DB char = Character() for x in aliases.charlist: print x[0] print x[1] char = Character.get_or_insert(str(x[0]), name=str(x[0]), avatarFile=str(x[1])) print char char.put() for ch in Character.query().order(Character.name).fetch(): print ch get_chars(True) self.response.write('Loaded DB')
def doggo_pathB(): global post_born_opt doggo_key = Character.query(Character.species == "Dog").get() doggo_pathB = Path.query(Path.owner == doggo_key.key).get() why = randrange(1,3) if born_opt == 1: if why == 1: return doggo_pathB.p_1b[0] elif why == 2: return doggo_pathB.p_1b[1] elif born_opt == 2: if why == 1: return doggo_pathB.p_2b[0] elif why == 2: return doggo_pathB.p_2b[1] elif born_opt == 3: if why == 1: return doggo_pathB.p_3b[0] elif why == 2: return doggo_pathB.p_3b[1]
def doggo_pre_pathB(): doggo_key = Character.query(Character.species == "Dog").get() doggo_pre_path = PPath.query(PPath.owner == doggo_key.key).get() return doggo_pre_path.PP_2
def panda_post_pathB(): panda_key = Character.query(Character.species == "Panda").get() panda_post_path = PPath.query(PPath.owner == panda_key.key).get() return panda_post_path.PP_2