--- a/src/egonomy/views.py Tue Mar 12 18:23:44 2013 +0100
+++ b/src/egonomy/views.py Wed Mar 13 18:27:37 2013 +0100
@@ -233,14 +233,13 @@
frg.coordinates = frg_path
# We build the svg xml
file = os.path.join(settings.MEDIA_ROOT, str(img.info.image_file))
- logger.debug(file)
- svg = '<svg preserveAspectRatio="none" width="476px" height="476px" viewBox="' + frg.viewbox_square +'" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">\n\
+ svg = '<svg preserveAspectRatio="none" width="100px" height="100px" viewBox="' + frg.viewbox_square +'" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">\n\
<defs>\n\
<clipPath id="fragment-clip">\n\
<path d="' + frg_path + '" />\n\
</clipPath>\n\
</defs>\n\
- <image xlink:href="' + file + '" x="0" y="0" preserveAspectRatio="none" width="1" height="1" opacity=".3"/>\n\
+ <image xlink:href="' + file + '" x="0" y="0" preserveAspectRatio="none" width="1" height="1" opacity=".1"/>\n\
<image xlink:href="' + file + '" x="0" y="0" preserveAspectRatio="none" width="1" height="1" clip-path="url(#fragment-clip)"/>\n\
</svg>'
# We save the svg file
@@ -269,57 +268,32 @@
else:
return HttpResponseForbidden("Failed to connect to Senseetive API (1)")
-# #We create the query
-# params = {
-# "xaction":"queries.create",
-# "xsessionid":session_id,
-# "query":"SELECT img._id FROM contentimages as img, requests as req WHERE img.desc1 cmp1 (file) req.image0",
-# }
-# req = requests.get(url=settings.SENSEETIVE_API_URL, params=params, verify=False)
-# return HttpResponse("session_id = " + session_id + ", req 0 .text = " + str(req.text))
-
- # We create the request and load the picture (ex queryid:50d0574a03000043102a5177, requestid:513f474c39b37bfa5b299a31)
- params = {
- 'image0':b64encode(open(os.path.join(settings.BATIK_RASTERIZER_TEMP_FOLDER, uid + '.png'), 'rb').read()),
- "xaction":"requests.create",
- "xsessionid":session_id,
- "queryid":"",
- "contentimageid":"",
- "requestid":"513f474c39b37bfa5b299a31",
- "requestfieldname":"image0"
+ # We create the contents.read request and load the picture
+ # (queryid 50d0574a03000043102a5177 for AS algorythm,
+ # 50d0574a0300000f102a5177 pigment)
+ # 50d0574a03000021102a5177 Gabor
+ files = {
+ 'image0':open(os.path.join(settings.BATIK_RASTERIZER_TEMP_FOLDER, uid + '.png'), 'rb').read(),
}
- req = requests.post(url=settings.SENSEETIVE_API_URL, data=params, verify=False)
- resp = req.json()
- if "id" in resp:
- request_id = resp["id"]
- else:
- return HttpResponseForbidden("Failed to connect to Senseetive API (2)")
-
-# # We read the request
-# params = {
-# "xaction":"requests.read",
-# "xsessionid":session_id,
-# "id":request_id
-# }
-# req = requests.post(url=settings.SENSEETIVE_API_URL, data=params, verify=False)
-# return HttpResponse("session_id = " + session_id + ", req 2 .text = " + str(req.text))
-
- # We read the contents
params = {
"xaction":"contents.read",
"xsessionid":session_id,
- "requestid":request_id,
- #"requestfieldname":"image0",
+ "queryid":"50d0574a03000043102a5177",
+ "_order_by_":"score",
+ "_row_first_":"0",
+ "_row_last_":"10",
+ "requestfieldname":"image0"
}
- req = requests.get(url=settings.SENSEETIVE_API_URL, params=params, verify=False)
+
+ req = requests.post(url=settings.SENSEETIVE_API_URL, data=params, files=files, verify=False)
+ #logger.debug(req.text)
resp = req.json()
if "contentlist" not in resp:
- return HttpResponseForbidden("Failed to connect to Senseetive API (3)")
+ return HttpResponseForbidden("Failed to connect to Senseetive API (3) : " + str(resp))
contents = resp["contentlist"]
keywords = []
for c in contents:
keywords += c["keywordlist"]
- #return HttpResponse("session_id = " + session_id + ", req 3 .text = " + str(len(contents)) + " found")
- #return HttpResponse("session_id = " + session_id + ", req 3 .text = " + req.text)
+
return HttpResponse(json.dumps(sorted(set(keywords))))