Mayumi_H

Display covid-19 status.lsl

Apr 19th, 2020
599
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //COVID-19のステータスをフローティングテキストに表示する
  2. //
  3. key request_id;
  4. string NumberFormat(string numberString){
  5.     string output;
  6.     integer x = 0;
  7.     integer numberStringLength = llStringLength(numberString);
  8.     integer z = (numberStringLength + 2) % 3;
  9.  
  10.     for(;x < numberStringLength; ++x)
  11.     {
  12.         output += llGetSubString(numberString, x, x);
  13.         if ((x % 3) == z && x != (numberStringLength - 1))
  14.             output += ",";
  15.     }
  16.  
  17.     return output;
  18. }
  19.  
  20. get_HTTP(){
  21.     //HTTPSでデータ取得(とりあえず一度で持ってこれるだけmax指定で)
  22.     request_id = llHTTPRequest("https://api.covid19api.com/summary",[HTTP_BODY_MAXLENGTH,16384],"");
  23. }
  24.  
  25. default{
  26.     on_rez(integer i){
  27.         llResetScript();
  28.     }
  29.  
  30.     state_entry(){
  31.         llSetText("", <1.0, 1.0, 1.0>, 1.0);
  32.         get_HTTP();
  33.         llSetTimerEvent(300.0);//とりあえず5分間隔で回す
  34.     }
  35.  
  36.     timer(){
  37.         get_HTTP();
  38.     }
  39.  
  40.     http_response(key id, integer status, list metadata, string body){
  41.         if(id == request_id){
  42.             if(status == 200){
  43.                 //正常だったら"Global"のデータだけにする(後ろが切れているのでそのままでは使えない)
  44.                 integer idx = llSubStringIndex(body,"}");
  45.                 body = llGetSubString(body,10,idx);
  46.                 //llOwnerSay(body);
  47.                 string s_NewConfirmed   = llJsonGetValue(body,["NewConfirmed"]);
  48.                 string s_TotalConfirmed = llJsonGetValue(body,["TotalConfirmed"]);
  49.                 string s_NewDeaths      = llJsonGetValue(body,["NewDeaths"]);
  50.                 string s_TotalDeaths    = llJsonGetValue(body,["TotalDeaths"]);
  51.                 string s_NewRecovered   = llJsonGetValue(body,["NewRecovered"]);
  52.                 string s_TotalRecovered = llJsonGetValue(body,["TotalRecovered"]);
  53.  
  54.                 string text;
  55.                 text += "NewConfirmed : "   +NumberFormat(s_NewConfirmed  ) + "\n";
  56.                 text += "TotalConfirmed : " +NumberFormat(s_TotalConfirmed) + "\n";
  57.                 text += "NewDeaths : "      +NumberFormat(s_NewDeaths     ) + "\n";
  58.                 text += "TotalDeaths : "    +NumberFormat(s_TotalDeaths   ) + "\n";
  59.                 text += "NewRecovered : "   +NumberFormat(s_NewRecovered  ) + "\n";
  60.                 text += "TotalRecovered : " +NumberFormat(s_TotalRecovered) + "\n";
  61.  
  62.                 llSetText(text, <1.0,1.0,1.0>, 1.0);
  63.             }else{
  64.                 llSay(0,"error code = " + (string)status);
  65.             }
  66.         }
  67.     }
  68. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×