Ejemplo n.º 1
0
class UserEndpoint(webapp.RequestHandler):
    def get(self):
        self.response.headers["Content-Type"] = "text/xml"
        op = util.getqsvalue('op')
        hood = util.getqsvalue('hood')
        oldusernames = util.getqsvalue('past')
        username = self.getusername()
        success = None
        if (op == 'add' and username is not None):
            try:
                success = self.adduser(username)
                a = ('response', [('username', username), ('score', 0),
                                  ('success', success)])
                self.response.out.write(util.toxml(a))
            except Exception, err:
                logging.error(err)
                self.response.out.write(
                    util.toxml(('response', [('success', False)])))

        elif (op == 'update' and hood is not None):
            try:
                success = self.updateuser(username, hood)
                a = ('response', [('username', username),
                                  ('success', success)])
                self.response.out.write(util.toxml(a))
            except Exception, err:
                logging.error(err)
                self.response.out.write(
                    util.toxml(('response', [('success', False)])))
Ejemplo n.º 2
0
	def get(self):
		self.response.headers["Content-Type"] = "text/xml"
		op = util.getqsvalue('op')
		hood = util.getqsvalue('hood')
		oldusernames = util.getqsvalue('past')
		username = self.getusername()
		success = None
		if (op == 'add' and username is not None):
			try:
				success = self.adduser(username)
				a=('response',[('username',username),('score',0),('success',success)])
				self.response.out.write(util.toxml(a))
			except Exception, err:
				logging.error(err)
				self.response.out.write(util.toxml(('response',[('success',False)])))
Ejemplo n.º 3
0
	def get(self):
		self.response.headers["Content-Type"] = "text/xml"
		op = util.getqsvalue('op')
		imageurl = util.getqsvalue('imageurl')
		hood = util.getqsvalue('hood', 'Mission')
		pageid = util.getqsvalue('pageid')
		latcoord = util.getqsvalue('latcoord')
		longcoord = util.getqsvalue('longcoord')
		username = util.getqsvalue('username', 'Anonymous')
		success = None
		
		if (op == 'get'):
			try:
				(success, pageid, imageurl, text, hood) = self.getimage(hood, username)
				a=('response',[('success',success),('pageid',pageid),('imageurl',imageurl),('imagetext',text),('neighborhood',hood)])
				self.response.out.write(util.toxml(a))
			except Exception, err:
				logging.error(err)
				self.response.out.write(util.toxml(('response',[('success',False)])))	
Ejemplo n.º 4
0
    def get(self):
        self.response.headers["Content-Type"] = "text/xml"
        op = util.getqsvalue('op')
        imageurl = util.getqsvalue('imageurl')
        hood = util.getqsvalue('hood', 'Mission')
        pageid = util.getqsvalue('pageid')
        latcoord = util.getqsvalue('latcoord')
        longcoord = util.getqsvalue('longcoord')
        username = util.getqsvalue('username', 'Anonymous')
        success = None

        if (op == 'get'):
            try:
                (success, pageid, imageurl, text,
                 hood) = self.getimage(hood, username)
                a = ('response', [('success', success), ('pageid', pageid),
                                  ('imageurl', imageurl), ('imagetext', text),
                                  ('neighborhood', hood)])
                self.response.out.write(util.toxml(a))
            except Exception, err:
                logging.error(err)
                self.response.out.write(
                    util.toxml(('response', [('success', False)])))
Ejemplo n.º 5
0
class ImageEndpoint(webapp.RequestHandler):
    def get(self):
        self.response.headers["Content-Type"] = "text/xml"
        op = util.getqsvalue('op')
        imageurl = util.getqsvalue('imageurl')
        hood = util.getqsvalue('hood', 'Mission')
        pageid = util.getqsvalue('pageid')
        latcoord = util.getqsvalue('latcoord')
        longcoord = util.getqsvalue('longcoord')
        username = util.getqsvalue('username', 'Anonymous')
        success = None

        if (op == 'get'):
            try:
                (success, pageid, imageurl, text,
                 hood) = self.getimage(hood, username)
                a = ('response', [('success', success), ('pageid', pageid),
                                  ('imageurl', imageurl), ('imagetext', text),
                                  ('neighborhood', hood)])
                self.response.out.write(util.toxml(a))
            except Exception, err:
                logging.error(err)
                self.response.out.write(
                    util.toxml(('response', [('success', False)])))

        elif (op == 'tag' and imageurl is not None and pageid is not None
              and latcoord is not None and longcoord is not None):
            try:
                success = self.tagimage(imageurl, pageid, latcoord, longcoord,
                                        hood, username)
                a = ('response', [('success', success)])
                self.response.out.write(util.toxml(a))
            except Exception, err:
                logging.error(err)
                self.response.out.write(
                    util.toxml(('response', [('success', False)])))
Ejemplo n.º 6
0
    def writescores(self, count):
        #do a gql query to get the top [count] users by scores desc
        q = UserModel.all()
        q.order('-count')
        results = q.fetch(int(count))
        logging.info(results)
        rank = 1
        a = []
        for user in results:
            b = ('user', [('username', user.username), ('score', user.count),
                          ('neighborhood', user.neighborhood)], {
                              'rank': rank
                          })
            a.append(b)
            rank = rank + 1

        c = ('response', [('users', a, {'page': count, 'found': rank - 1})])

        self.response.out.write(util.toxml(c))
Ejemplo n.º 7
0
    def writescores(self, count):
        # do a gql query to get the top [count] users by scores desc
        q = UserModel.all()
        q.order("-count")
        results = q.fetch(int(count))
        logging.info(results)
        rank = 1
        a = []
        for user in results:
            b = (
                "user",
                [("username", user.username), ("score", user.count), ("neighborhood", user.neighborhood)],
                {"rank": rank},
            )
            a.append(b)
            rank = rank + 1

        c = ("response", [("users", a, {"page": count, "found": rank - 1})])

        self.response.out.write(util.toxml(c))
Ejemplo n.º 8
0
				self.response.out.write(util.toxml(('response',[('success',False)])))	
						
		elif (op == 'tag' and imageurl is not None and pageid is not None and latcoord is not None and longcoord is not None):
			try:
				success = self.tagimage(imageurl, pageid, latcoord, longcoord, hood, username)
				a=('response',[('success',success)])
				self.response.out.write(util.toxml(a))
			except Exception, err:
				logging.error(err)
				self.response.out.write(util.toxml(('response',[('success',False)])))	
						
		elif (op == 'ignore' and imageurl is not None and username is not None):
			try:
				success = self.ignoreimage(imageurl, username)
				a=('response',[('success',success)])
				self.response.out.write(util.toxml(a))	
			except Exception, err:
				logging.error(err)
				self.response.out.write(util.toxml(('response',[('success',False)])))
				
		#else:
			#self.response.out.write(util.toxml(('response',[('success',False)])))
			
	def getimage(self, hood, username):
		
		modelimage = self.getfirstuntaggedimage(username, hood)		
		if (modelimage != None):		
			logging.info("Got image %s", modelimage.imageurl)
			imageinfo = self.getwikiimageurl(modelimage)
			imageurl = ""
			
Ejemplo n.º 9
0
            try:
                success = self.tagimage(imageurl, pageid, latcoord, longcoord,
                                        hood, username)
                a = ('response', [('success', success)])
                self.response.out.write(util.toxml(a))
            except Exception, err:
                logging.error(err)
                self.response.out.write(
                    util.toxml(('response', [('success', False)])))

        elif (op == 'ignore' and imageurl is not None
              and username is not None):
            try:
                success = self.ignoreimage(imageurl, username)
                a = ('response', [('success', success)])
                self.response.out.write(util.toxml(a))
            except Exception, err:
                logging.error(err)
                self.response.out.write(
                    util.toxml(('response', [('success', False)])))

        #else:
        #self.response.out.write(util.toxml(('response',[('success',False)])))

    def getimage(self, hood, username):

        modelimage = self.getfirstuntaggedimage(username, hood)
        if (modelimage != None):
            logging.info("Got image %s", modelimage.imageurl)
            imageinfo = self.getwikiimageurl(modelimage)
            imageurl = ""