def post(self): #self.response.headers['Content-Type'] = 'text/plain' userinfo = self.request.get("username") passwd = self.request.get("pass") devType = self.request.get("devtype") macInfo = self.request.get("macinfo") print "userinfo = " + userinfo print "pass = "******"devtype = " + devType print "macInfo = " + macInfo curUser = EvUsers.isUserValid(userinfo,passwd) if (True == curUser): print "user right" curDev = EvScannerDev.query(ndb.AND(EvScannerDev.devType==devType,EvScannerDev.macInfo==macInfo)).get() if curDev: #exists print "dev exist" self.response.status = 200 return self.response else: print "add new dev" newDev = EvScannerDev() newDev.macInfo = macInfo newDev.devType = devType newDev.createDate = datetime.datetime.now() newDev.put() self.response.status = 200 return self.response else: #error user self.response.status = 404 return self.response
def get(self): userinfo = self.request.get("username") passwd = self.request.get("pass") devType = self.request.get("devtype") macInfo = self.request.get("macinfo") temp = ndb.GeoPt(-1.15, -1.89) print "temp = " + str(temp) curUser = EvUsers.query(ndb.AND(EvUsers.username==userinfo,EvUsers.password==passwd)).get() if (curUser): curDev = EvScannerDev.query(ndb.AND(EvScannerDev.devType==devType,EvScannerDev.macInfo==macInfo)).get() print "user right" if curDev: #build html print "device right" impl = getDOMImplementation() document = impl.createDocument(None, None, None) devices = document.createElement("devices") device = document.createElement("device") updateTime = document.createElement("updateTime") geoInfo = document.createElement("geoinfo") document.appendChild(devices) updateTime.appendChild(document.createTextNode(str(curDev.lastUpdateDate))) geoInfo.appendChild(document.createTextNode(str(curDev.lastPlace))) device.appendChild(updateTime) device.appendChild(geoInfo) devices.appendChild(device) self.response.headers['Content-Type'] = 'text/plain' self.response.write(document.toprettyxml()) else: self.response.status = 404 return self.response else: self.response.status = 404 return self.response
def post(self): ''' ''' print "body = " + str(self.request.body) doc = xml.dom.minidom.parseString(self.request.body) top = doc.getElementsByTagName("devices") devices = top[0].getElementsByTagName("device") for device in devices: print "get device" eleDevType = device.getElementsByTagName("devtype") eleMacInfo = device.getElementsByTagName("macinfo") eleGeo = device.getElementsByTagName("geoinfo") devType = getText(eleDevType[0].childNodes) macInfo = getText(eleMacInfo[0].childNodes) geoInfo = getText(eleGeo[0].childNodes) print "get devType = " + devType print "get macInfo = " + macInfo print "get geoInfo = " + geoInfo lan_str,log_str = geoInfo.split(',') lan = float(lan_str) log = float(log_str) print "lan = " + str(lan) print "log = " + str(log) curDev = EvScannerDev.query(ndb.AND(EvScannerDev.devType==devType,EvScannerDev.macInfo==macInfo)).get() if curDev: curDev.lastUpdateDate = datetime.datetime.now() curDev.lastPlace = ndb.GeoPt(lan, log) curDev.put() self.response.status = 200 return self.response else: self.response.status = 404 return self.response
def post(self): #self.response.headers['Content-Type'] = 'text/plain' userinfo = self.request.get("username") passwd = self.request.get("pass") devType = self.request.get("devtype") macInfo = self.request.get("macinfo") print "userinfo = " + userinfo print "pass = "******"devtype = " + devType print "macInfo = " + macInfo curUser = EvUsers.isUserValid(userinfo, passwd) if (True == curUser): print "user right" curDev = EvScannerDev.query( ndb.AND(EvScannerDev.devType == devType, EvScannerDev.macInfo == macInfo)).get() if curDev: #exists print "dev exist" self.response.status = 200 return self.response else: print "add new dev" newDev = EvScannerDev() newDev.macInfo = macInfo newDev.devType = devType newDev.createDate = datetime.datetime.now() newDev.put() self.response.status = 200 return self.response else: #error user self.response.status = 404 return self.response