image analysis running on the server "lev", sharing the basic same data. presently, the IA port is not exposed, but in interest of time, i am making a "pass-through" access to the IA api via a WB api call. (this is ultimately the model we want to use in production, so that wildbook can handle security and other issues, but as you will see, i have kind of done a very generic hack version of the same concept.) this consists of a small wb api "wrapper" call around the call you actually wish to be making of the IA data. perhaps examples would demonstrate best:

IA call: /api/annot/image/contributor/tag/json/?annot_uuid_list=[{"UUID":"8b595dc0-9c5a-4caf-9703-9f8ff017e824"}] becomes: http://lev.cs.rpi.edu:8080/ggr/ia?passthru=/api/annot/image/contributor/tag/json/&arg=annot_uuid_list%3D[{%22__UUID__%22:%228b595dc0-9c5a-4caf-9703-9f8ff017e824%22}]

IA call: /api/annot/age/months/json/?annot_uuid_list=[{"UUID":"8b595dc0-9c5a-4caf-9703-9f8ff017e824"}] becomes: http://lev.cs.rpi.edu:8080/ggr/ia?passthru=/api/annot/age/months/json/&arg=annot_uuid_list%3D[{%22__UUID__%22:%228b595dc0-9c5a-4caf-9703-9f8ff017e824%22}]

in other words, you pass two parameters, passthru and arg, which are just uri-encoded strings that represent the two sides of the "?" in the original call. (note that arg is optional.) the two examples above are "live", in the sense that you can click them and should get the json results as expected.

this should, technically, get you to any existing IA api call (provided i had jason p turn on all the right ones)... at least the ones that use GET. if you need any POST queries, let me know and i can pass those through as well.


In [18]:
import requests
import urllib
import GetPropertiesAPI as GP
from collections import OrderedDict
import importlib
importlib.reload(GP)
DOMAIN = 'http://lev.cs.rpi.edu:8080/ggr/ia'

In [ ]:
## /api/annot/image/contributor/tag/json/?annot_uuid_list=[{"__UUID__":"8b595dc0-9c5a-4caf-9703-9f8ff017e824"}]


param = urllib.parse.quote('annot_uuid_list=') + '[{' + urllib.parse.quote('"__UUID__"') + ':' +urllib.parse.quote('"8b595dc0-9c5a-4caf-9703-9f8ff017e824"') + '}]'
# param = urllib.parse.urlencode(param)

In [ ]:
payload = OrderedDict([('passthru', u'/api/annot/age/months/json/'), 
                ('asdasarg', param)]) 
response = requests.get(DOMAIN , 
                        params = payload 
                        )

In [8]:
url = DOMAIN + '?passthru=' +"/api/annot/age/months/json" + '&arg=' + GP.ggr_annot_form_arg('3f814994-216c-4015-9af3-f286481414c0')

In [9]:
res = requests.get(url)
# "/api/annot/age/months/json" - age
# "/api/annot/sex/json/" - sex
# "/api/annot/name/rowid/json/" - NID
#

In [10]:
res.json()


Out[10]:
{'results': [[None, 2]], 'success': True}

In [ ]:
url = DOMAIN + '?passthru=' +"/api/annot/age/months/json/" + '&arg=' + ggxr_form_arg("8b595dc0-9c5a-4caf-9703-9f8ff017e824")

In [ ]:
s = "abcd"

'\"%s\"' %s

In [ ]:
ggr_form_arg = lambda x : urllib.parse.quote('annot_uuid_list=') + '[{' + urllib.parse.quote('"__UUID__"') + ':' + urllib.parse.quote('\"%s\"' %x) + '}]'

In [ ]:
ggr_image_form_arg = lambda x : urllib.parse.quote('image_uuid_list=') + '[{' + urllib.parse.quote('"__UUID__"') + ':' + urllib.parse.quote('\"%s\"' %x) + '}]'

In [48]:
import UploadAndDetectIBEIS as UD, uuid
import requests, json, datetime, urllib, importlib
importlib.reload(UD)

import GetPropertiesAPI as GP
importlib.reload(GP)


Out[48]:
<module 'GetPropertiesAPI' from '/Users/sreejithmenon/Google Drive/CodeBase/AWESOME/script/GetPropertiesAPI.py'>

In [ ]:
data_dict = {
        'gid_list': [1],
    }
image_uuid_list = UD.get('api/image/uuid', data_dict)
image_uuid_dict = image_uuid_list[0]
image_uuid = uuid.UUID(image_uuid_dict['__UUID__'])

data_dict = {
    'query_annot_uuid_list' : [1],
    'query_annot_name_list' : [image_uuid]
    
}
res = requests.get('http://pachy.cs.uic.edu:5000/api/engine/query/graph/', data = data_dict)
res.json()

In [ ]:
data_dict = {
        'aid_list': [1],
    }
image_uuid_list = UD.get('api/annot/uuid', data_dict)
image_uuid_list

In [ ]:
res = requests.get('http://pachy.cs.uic.edu:5001/api/annot/uuid/', 
                   data = dict(aid_list=['1']))


print(res.json())

res = requests.get('http://pachy.cs.uic.edu:5000/api/annot/uuid/', 
                   data = dict(aid_list=['15441']))


print(res.json())

In [ ]:
url = "http://pachy.cs.uic.edu:5001/api/engine/query/graph/"
data_dict = {
    'query_annot_uuid_list' : json.dumps([{'__UUID__': '2637b5e7-2a41-4aea-9dbd-dfe186cc8c8c'}]),
}
response = requests.request('POST', url, data=data_dict)

In [ ]:
response.json()

In [ ]:
d['json_result']['inference_dict']['cluster_dict']

In [ ]:
d['json_result']['inference_dict']['annot_pair_dict']

In [ ]:
re.findall(r'NEWNAME_(\d+)', 'NEWNAME_-6')

In [16]:
import os, json, re

In [ ]:
data_dict = {
        'gid_list': list(range(1702, 1792)),
    }

UD.delete('api/image',data_dict)

In [33]:
with open("../data/beauty_ggr.json", "r") as bty_ggr_fl:
    bty_ggr= json.load(bty_ggr_fl)
    
keys = list(bty_ggr.keys())

In [16]:
import BuildConsolidatedFeaturesFile as BCF
import importlib
importlib.reload(BCF)
import urllib

In [58]:
uuid_annot_map = BCF.build_feature_file_ggr(None, "/tmp/test")

In [17]:
aid_uuid_list = [item for sublist in list(uuid_annot_map.values()) for item in sublist if item]

In [18]:
aid_uuid_list


Out[18]:
['9849a3a0-a8de-4c0a-b5db-4fa690a3578e',
 '146eab19-1ac4-46b0-90d0-72d4471fce76',
 '046bd8aa-8f77-4ae4-8048-04d86063879a',
 'ae0730b9-816f-45fb-ba5d-c45b2fdd79fe',
 'e41701a3-cb30-4739-bbeb-c35f46f40719',
 '48ad9ae8-43f2-499b-8755-b7e155212f61',
 'd66d3dcf-11fd-4a3d-8522-f39e9eb0934b',
 'b40ccf2a-3744-4e12-9a38-bab7311a5a19',
 'fd7d18ba-a66a-4e79-8daa-58e0790b6e99',
 'c47b15cb-3f18-4305-85b5-0d7fe67e02cc',
 'e62eaa9c-6e6c-4ee6-ad64-5ea64a179d6f',
 '34d11736-9ed7-45c8-aa5c-e82103901130']

In [22]:
ggr_image_form_arg = lambda x : urllib.parse.quote('image_uuid_list=') + '[{' + urllib.parse.quote('"__UUID__"') + ':' + urllib.parse.quote('\"%s\"' %x) + '}' + ',{' + urllib.parse.quote('"__UUID__"') + ':' + urllib.parse.quote('\"%s\"' %x) + '}]'

In [49]:
GP.ggr_image_form_arg('9849a3a0-a8de-4c0a-b5db-4fa690a3578e')


Out[49]:
'image_uuid_list%3D[{%22__UUID__%22:%229849a3a0-a8de-4c0a-b5db-4fa690a3578e%22}]'

In [27]:
ggr_image_form_arg = lambda x : urllib.parse.quote('image_uuid_list=') + '[{' + urllib.parse.quote('"__UUID__"') + ':' + urllib.parse.quote('\"%s\"' %x) + '}]'

In [46]:
ggr_image_form_arg('9849a3a0-a8de-4c0a-b5db-4fa690a3578e')

data = json.dumps({
"passthru" : "/api/image/annot/uuid", 
"arg" : {
    'image_uuid_list' : json.dumps([{"__UUID__" : "9849a3a0-a8de-4c0a-b5db-4fa690a3578e" }])
}
})
req = requests.request("GET", url=DOMAIN, data=data)

In [16]:
ggr_contrib_form_arg = lambda x : urllib.parse.quote('contributor_tag_list=') + '[' + urllib.parse.quote('\"%s\"' %x) + ']'

In [14]:
import json

DOMAIN + "?passthru=/api/contributor/gids/unixtime/?gid_list="+ json.dumps([1])

GP.ggr_get("/api/image/note/?gid_list=[1]")


Out[14]:
{'results': ['GGR,100,A,00000'], 'success': True}

In [18]:
# GGR.get("/api/contributor/gids/unixtime")


ggr_contrib_form_arg("GGR,100,A,00000")


Out[18]:
'contributor_tag_list%3D[%22GGR%2C100%2CA%2C00000%22]'

In [19]:
GP.ggr_annot_form_arg('blah')


Out[19]:
'annot_uuid_list%3D[{%22__UUID__%22:%22blah%22}]'

In [22]:
url = DOMAIN + "?passthru=" + "/api/contributor/gids/unixtime" + "&arg=" + "contributor_tag_list%3D[%22GGR%2C100%2CA%2C00000%22]"

In [23]:
url


Out[23]:
'http://lev.cs.rpi.edu:8080/ggr/ia?passthru=/api/contributor/gids/unixtime&arg=contributor_tag_list%3D[%22GGR%2C100%2CA%2C00000%22]'

In [24]:
# 45775b50-cb67-51d0-a6a6-3dd88f4fbde2

GP.ggr_get("/api/image/lon", GP.ggr_image_form_arg("45775b50-cb67-51d0-a6a6-3dd88f4fbde2"))


Out[24]:
{'exception': 'java.lang.RuntimeException: Failed : HTTP error code : 500',
 'success': False}

In [34]:
import re

keys = [re.findall(r'(.*).jpg', key)[0] for key in keys]

key_dash = keys[:10]

In [43]:
uuid_gid_map = {GP.ggr_get("/api/image/uuid/?gid_list=[%i]" %gid)['results'][0]["__UUID__"] : gid for gid in range(1,37434)}

In [40]:
for i in range(1,11):
    print(GP.ggr_get("/api/image/uuid/?gid_list=[%i]" %i)['results'][0]["__UUID__"])


5ee9cb4b-b4fa-bec5-cca0-31c341d58730
c861876f-66f4-fec7-f9b5-a97314ba3647
01e3b8d2-a80d-547d-8897-ebb900e00595
85f7c1c4-77fc-8b53-83c3-56bbda156da4
f834d0d9-0fd5-c222-2419-eebb5deb090b
36fc39fa-d931-536a-6a70-4aab322b906c
ca0e8c7d-8758-160a-f089-8df3c208db85
e1f85f87-6f9c-c4d0-330d-f82b81e8ab8e
f611b15d-1e8c-a500-e8ab-d75322da209e
f42ca8c2-f653-0f54-0653-3514e6ea1e1b

In [52]:
with open("/tmp/uuid_gid_map.json", "w") as fl:
    json.dump(uuid_gid_map, fl, indent=4)


uuid_gid_map


Out[52]:
{'01e3b8d2-a80d-547d-8897-ebb900e00595': 3,
 '36fc39fa-d931-536a-6a70-4aab322b906c': 6,
 '5ee9cb4b-b4fa-bec5-cca0-31c341d58730': 1,
 '85f7c1c4-77fc-8b53-83c3-56bbda156da4': 4,
 'c861876f-66f4-fec7-f9b5-a97314ba3647': 2,
 'ca0e8c7d-8758-160a-f089-8df3c208db85': 7,
 'e1f85f87-6f9c-c4d0-330d-f82b81e8ab8e': 8,
 'f42ca8c2-f653-0f54-0653-3514e6ea1e1b': 10,
 'f611b15d-1e8c-a500-e8ab-d75322da209e': 9,
 'f834d0d9-0fd5-c222-2419-eebb5deb090b': 5}

In [45]:
ggr_gid_form_arg = lambda x : urllib.parse.quote('gid_list=') + '[' + urllib.parse.quote('\"%s\"' %x)  + ']'

In [47]:
ggr_gid_form_arg("1")


Out[47]:
'gid_list%3D[%221%22]'

In [49]:
lat = GP.ggr_get("/api/image/lat", GP.ggr_gid_form_arg(1))

In [50]:
lat


Out[50]:
{'results': [0.27842], 'success': True}

In [17]:
BCF.build_exif_ftrs_fl_ggr("../data/uuid_gid_map.json", 
                           "../data/ggr_uuid_list.dat",
                           "/tmp/test_exif.json", 1, 10)


100 seconds elapsed..!
100 seconds elapsed..!
100 seconds elapsed..!
Out[17]:
0

In [57]:
len(keys)


Out[57]:
37433

In [58]:
str(u'01e3b8d2-a80d-547d-8897-ebb900e00595')


Out[58]:
'01e3b8d2-a80d-547d-8897-ebb900e00595'

In [59]:
GP.ggr_get("/api/image/annot/uuid/json", GP.ggr_image_form_arg("c6d2bfe6-629b-dcf3-4329-987968a833ee"))


Out[59]:
{'results': [[]], 'success': True}

In [60]:
with open("../data/uuid_gid_map.json", "r") as fl:
    lst = list(json.load(fl).keys())
    
    
with open("../data/ggr_uuid_list.dat", "w") as f2:
    f2.write("\n".join(lst))

In [19]:
uuid_gid_map = {GP.ggr_get("/api/image/uuid/?gid_list=[%i]" %gid)['results'][0]["__UUID__"] : gid for gid in range(1,40811)}


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/Users/sreejithmenon/anaconda/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    384             try:  # Python 2.7, use buffering of HTTP responses
--> 385                 httplib_response = conn.getresponse(buffering=True)
    386             except TypeError:  # Python 2.6 and older

TypeError: getresponse() got an unexpected keyword argument 'buffering'

During handling of the above exception, another exception occurred:

KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-19-734e7a1b4d30> in <module>()
----> 1 uuid_gid_map = {GP.ggr_get("/api/image/uuid/?gid_list=[%i]" %gid)['results'][0]["__UUID__"] : gid for gid in range(1,37434)}

<ipython-input-19-734e7a1b4d30> in <dictcomp>(.0)
----> 1 uuid_gid_map = {GP.ggr_get("/api/image/uuid/?gid_list=[%i]" %gid)['results'][0]["__UUID__"] : gid for gid in range(1,37434)}

/Users/sreejithmenon/Google Drive/CodeBase/AWESOME/script/GetPropertiesAPI.py in ggr_get(passthru, arg)
     83         url = ggr_base + "?passthru=" + passthru
     84 
---> 85     response = requests.get(url)
     86 
     87     return response.json()

/Users/sreejithmenon/anaconda/lib/python3.5/site-packages/requests/api.py in get(url, params, **kwargs)
     69 
     70     kwargs.setdefault('allow_redirects', True)
---> 71     return request('get', url, params=params, **kwargs)
     72 
     73 

/Users/sreejithmenon/anaconda/lib/python3.5/site-packages/requests/api.py in request(method, url, **kwargs)
     55     # cases, and look like a memory leak in others.
     56     with sessions.Session() as session:
---> 57         return session.request(method=method, url=url, **kwargs)
     58 
     59 

/Users/sreejithmenon/anaconda/lib/python3.5/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    473         }
    474         send_kwargs.update(settings)
--> 475         resp = self.send(prep, **send_kwargs)
    476 
    477         return resp

/Users/sreejithmenon/anaconda/lib/python3.5/site-packages/requests/sessions.py in send(self, request, **kwargs)
    583 
    584         # Send the request
--> 585         r = adapter.send(request, **kwargs)
    586 
    587         # Total elapsed time of the request (approximately)

/Users/sreejithmenon/anaconda/lib/python3.5/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    401                     decode_content=False,
    402                     retries=self.max_retries,
--> 403                     timeout=timeout
    404                 )
    405 

/Users/sreejithmenon/anaconda/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, **response_kw)
    576                                                   timeout=timeout_obj,
    577                                                   body=body, headers=headers,
--> 578                                                   chunked=chunked)
    579 
    580             # If we're going to release the connection in ``finally:``, then

/Users/sreejithmenon/anaconda/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    385                 httplib_response = conn.getresponse(buffering=True)
    386             except TypeError:  # Python 2.6 and older
--> 387                 httplib_response = conn.getresponse()
    388         except (SocketTimeout, BaseSSLError, SocketError) as e:
    389             self._raise_timeout(err=e, url=url, timeout_value=read_timeout)

/Users/sreejithmenon/anaconda/lib/python3.5/http/client.py in getresponse(self)
   1195         try:
   1196             try:
-> 1197                 response.begin()
   1198             except ConnectionError:
   1199                 self.close()

/Users/sreejithmenon/anaconda/lib/python3.5/http/client.py in begin(self)
    295         # read until we get a non-100 response
    296         while True:
--> 297             version, status, reason = self._read_status()
    298             if status != CONTINUE:
    299                 break

/Users/sreejithmenon/anaconda/lib/python3.5/http/client.py in _read_status(self)
    256 
    257     def _read_status(self):
--> 258         line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    259         if len(line) > _MAXLINE:
    260             raise LineTooLong("status line")

/Users/sreejithmenon/anaconda/lib/python3.5/socket.py in readinto(self, b)
    573         while True:
    574             try:
--> 575                 return self._sock.recv_into(b)
    576             except timeout:
    577                 self._timeout_occurred = True

KeyboardInterrupt: 

In [ ]:
import requests
import UploadAndDetectIBEIS as UD
data