One Name2key Service to Rule Them All
January 23 2010, 6:09 PMToday I was reading Ordinal Malaprop's blog post about her new tool to distribute an item to a list of avatar names. Her script goes to great lengths to turn avatar names into keys, trying 3 or 4 different name2key services before giving up if a key can't be found. That sounded to me like more work than an LSL script should reasonably have to do, so I have created a name2key service that is designed to alleviate the concerns that motivate such redundancy.
The Gridapps Name/Key Lookup Service
The service is designed to be used from LSL scripts or by other programs. To look up a key from my service, make an http request like this:http://gridapps.appspot.com/lookups/name2key/schmobag%20hogfatherJust replace the "schmobag%20hogfather" part with the url-encoded name of the person whose key you're looking for.
Under the hood, my lookup service does the following:
- Checks its local memory cache for the avatar you're looking for. If found, it returns the key immediately. If not, then it...
- Queries its Google App Engine datastore for the avatar. If it's in there, it returns it to you, and saves a copy in memcache for super-fast results if you query that name again soon. If the name is not found in the datastore, then it...
- Looks for the name on search.secondlife.com and web scrapes the results. If the avatar is found, then the name and key are stored in memcache and the datastore so that the service will never have to hit the Second Life servers again to look up that name. If the avatar doesn't exist then it throws up its hands and returns a 404 status not found error (you can watch for status 404 in your code to know if a lookup failed).
Why Use This One?
There are a lot of name2key services out there. So why pick this one? A few reasons:- It's accurate. If a name exists in Second Life search, this service can get the key for you.
- It's gentle to the SL servers. Unlike services that scrape search.secondlife.com for every single lookup, the Gridapps lookup service will only ever hit the search site once to find a name. Every subsequent lookup for that name will be served from the datastore.
- It's fast. For avatars found in memcache or the datastore, results are returned almost instantly.
But Wait There's More
Gridapps provides two more lookup services of particular use to those building SL-integrated web applications. The first is key2name:Requesting this:Just as you'd expect. Key2name lookups present one difficulty for the web scraping technique used by Gridshout and other services: private profiles. If a person's SL profile is set to private, then you can't navigate to it via the web interface using their key to look up their name. Private profiles do not affect name2key lookups though, because for those you just search for the name and scrape the results list, which includes even private profiles.
http://gridapps.appspot.com/lookups/key2name/e67abce6-e6d6-4740-a067-4b53cb2c4ad7
Returns this:
Schmobag Hogfather
This is where Gridapps datastore-backed design comes to the rescue. If an avatar is in the datastore, the Gridapps service will be able to return a key2name result even if the person's profile is set to private, because no scraping is needed. A Gridapps key2name lookup will fail only if 1) the avatar's SL profile is set to private, AND 2) the service has never done a name2key lookup on that avatar.
The last lookup service is handy for those building their own user databases, who want to make sure their user names are correct. The name2key_name service returns both an avatar's key and the correctly-capitalized name:
Requesting this:This is useful if your avatar name comes from user input, and you're not sure if they've capitalized it correctly. Using this kind of lookup, you can get the exact name without having to do a name2key and then a separate key2name.
http://gridapps.appspot.com/lookups/name2key_name/schmobag%20hogfather
Returns this:
e67abce6-e6d6-4740-a067-4b53cb2c4ad7, Schmobag Hogfather