Ruthven Willenov

Retrieve Group Name - With HTML Cleanup

Recommended Posts

Posted (edited)

This a simple, proof of concept script for retrieving the name of a group that an object is assigned to. To get an avatar's group, you can first grab a uuid of one of their attachments with llGetAttachedList, then pass that too llGetObjectDetails in place of llGetKey()

 

this script retreives the uuid of the object's group, then sends an http request to get the group's info on the SecondLife website. Once it receives the response, it parses out <title> and </title> to get the groups name. some groups use special characters in their name, such as less than and greater than. the html formats those into HTML entities, and llUnescapeURL doesn't know how to convert those. The loop will parse out the entitie names and replace them with the correct character from the list. it's a short list. perhaps someone has a full list of characters that will/will not convert in this case?

 

default
{
    state_entry()
    {
        list dets = llGetObjectDetails(llGetKey(),[OBJECT_GROUP]);
        key uuid = llList2Key(dets,0);
        llHTTPRequest("http://world.secondlife.com/group/"+(string)uuid,[],"");
   }

    http_response(key id, integer status, list data, string body)
    {
        list parsed = llParseString2List(body,["<title>","</title>"],[]);
        string groupname = llList2String(parsed,1);
        list parsedname = llParseString2List(groupname,[],["&lt;","&rt;","&quote;","&amp;","&cent;","&pound;","&yen;","&euro;","&copy;","&reg;"]);
        integer len = llGetListLength(parsedname);
        integer i;
        list replace = ["&lt;","<","&rt;",">","&quote;","\"","&amp;","&","&cent;","¢","&pound;","£","&yen;","¥","&euro;","€","&copy;","©","&reg;","®"];
        for(i = 0;i < len;i++)
        {
            string substring = llList2String(parsedname,i);
            integer idx = llListFindList(replace,[substring]);
            if(~idx && !(idx%2))
            {
                parsedname = llListReplaceList(parsedname,llList2List(replace,idx+1,idx+1),i,i);
            }
        }
        groupname = llDumpList2String(parsedname,"");
        llSetText(groupname,<1,0,1>,1.0);
    }
}

 

 

Edited by Ruthven Willenov
  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

I know, it could be an endless list on the parsing, but more characters from ISO-8859-1 in code range 160-191( for example &acute ), would catch most Western letters and display text correct in SL.

Edited by Rachel1206

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now