Ejemplo n.º 1
0
    def process_response(self, result):
        #print " ******** result =", result
        docs = []
        rootDocs = []
        docsDict = {}
        # Build a dictionary of the annotations
        for doc in result:
            #hack is done here to replace [] with null as json.py does not properly parse 
            jsonStr = unicode(doc.get("jsonString").replace("[]", "null")).encode("utf-8")
            doc = json.read(jsonStr)
            doc["replies"] = []
            docs.append(doc)
            docsDict[doc["uri"]] = doc
            if doc["annotates"]["uri"] == doc["annotates"]["rootUri"]:
                rootDocs.append(doc)

        # Now process the dictionary
        for doc in docs:
            # If we are NOT a top level annotation
            if doc["annotates"]["uri"] != doc["annotates"]["rootUri"]:
                # Find what we are annotating
                try:
                    d = docsDict[doc["annotates"]["uri"]]
                    d["replies"].append(doc) # Add ourselves to its reply list
                except:
                    # TODO KeyError
                    pass
        return json.write(rootDocs)
Ejemplo n.º 2
0
    def process_response(self, result):
        #print " ******** result =", result
        docs = []
        rootDocs = []
        docsDict = {}
        # Build a dictionary of the annotations
        for doc in result:
            #hack is done here to replace [] with null as json.py does not properly parse
            jsonStr = unicode(doc.get("jsonString").replace(
                "[]", "null")).encode("utf-8")
            doc = json.read(jsonStr)
            doc["replies"] = []
            docs.append(doc)
            docsDict[doc["uri"]] = doc
            if doc["annotates"]["uri"] == doc["annotates"]["rootUri"]:
                rootDocs.append(doc)

        # Now process the dictionary
        for doc in docs:
            # If we are NOT a top level annotation
            if doc["annotates"]["uri"] != doc["annotates"]["rootUri"]:
                # Find what we are annotating
                try:
                    d = docsDict[doc["annotates"]["uri"]]
                    d["replies"].append(doc)  # Add ourselves to its reply list
                except:
                    # TODO KeyError
                    pass
        return json.write(rootDocs)
Ejemplo n.º 3
0
	def GET(self):
		web.header('content-type','text/html;charset=utf-8',unique=True)
		if not checkPasswd():
			return "Not Logged In"
		boardList = board.getBoardsByUser(web.input()["user"])
		boardListDetailed = []
		boardDict = board.getBoardsDict()
		for i in boardList:
			d = boardDict[i]
			d2 = {}
			d2["board"] = d["filename"]
			d2["chineseName"] = board.getBoardChineseName(d["filename"])
			d2["bm"] = d["BM"]
			boardListDetailed.append(d2)
		return json2.write(boardListDetailed)
Ejemplo n.º 4
0
    def export_json(self, fname="nudraw.json"):
        if len(self.objects) == 0:
            raise ValueError("No objects defined")
        f = open(fname, "w")
        maxp, minp = self.get_extremepoints()

        width = maxp[0] - minp[0]
        height = maxp[1] - minp[1]

        mx = max([width, height])
        mn = min([width, height])
        fac = 0.65 + math.e**(-0.65 * numpy.log10(math.sqrt(mn)))
        #~ print "width=%f, height=%f, mn=%f, fac=%f"%(width,height, mn, fac)

        camera = numpy.array([(maxp[0] + minp[0]) / 2, (maxp[1] + minp[1]) / 2,
                              fac * mx])
        light = numpy.array([(maxp[0] + minp[0]) / 2,
                             150 + (maxp[1] + minp[1]) / 2,
                             -max([width, height]) / 2])

        #~ print "camera=%s"%camera

        scene = self.objects[0].json_scene
        lookat = map(float, camera)
        lookat[2] = 0.0
        scene["camera"] = {
            "position": map(float, camera),
            "lookat": lookat,
            "updir": [0., 1., 0.]
        }

        scene["lights"].append({
            "position": map(float, camera),
            "color": [0., 1., 0.]
        })

        for obj in self.objects:
            obj.export_json()
        #~ print json
        #~ print dir(json)
        f.write(json.write(scene))
        f.close()
Ejemplo n.º 5
0
	def GET(self):
		web.header('content-type','text/json;charset=utf-8',unique=True)
		if not checkPasswd():
			return "Not Logged In"
		start = ("start" in web.input() and int(web.input()["start"]) or 1)
		cnt = ("cnt" in web.input() and web.input()["cnt"] or 20)
		b = web.input()["board"]
		boardPostsLists = board.getPostsList(b)
		l = []
		for i in range(start-1,start+cnt-1):
			if i >= len(boardPostsLists):
				break
			t = {}
			t["filename"] = boardPostsLists[i]["filename"][:14]
			t["No"] = i+1
			t["title"] = boardPostsLists[i]["title"]
			t["owner"] = boardPostsLists[i]["owner"]
			t["id"] = boardPostsLists[i]["id"]
			t["reid"] = boardPostsLists[i]["reid"]
			t["content"] = functions.GBK2UTF(post.getPostNoCT(b,t["filename"]))
			l.append(t)
		if len(l) == 0:
			return str(len(boardPostsLists)+1)
		return json2.write(l)