SHARE
TWEET

get_MoWaS_warnings_json.js

toxictaste Oct 10th, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(jsonString) {
  2.     var regional_code='083170000000';
  3.     var root_key=["identifier","sender","sent","status","msgType","scope","code"];
  4.     var info_key=["language","category","event","responseType","urgency","severity","certainty","headline","description","instruction","web","contact"];
  5.     var test_key={"valueName":"","value":""};
  6.     jsonString = jsonString.replace(/[<]br[^>]*[>]/gi," ");                                                            
  7.     var newJSON = JSON.parse(jsonString);
  8.     var jsonResult = 'NULL';
  9.     for (var i = 0; i < newJSON.length; i++) {
  10.        
  11.         for (var e = 0; e < (newJSON[i]['info'][0]['area'][0]['geocode']).length; e++) {
  12.            
  13.         if (newJSON[i]['info'][0]['area'][0]['geocode'][e].value == regional_code) {
  14.             if ((newJSON[i]['info'][0]['headline']).indexOf('Entwarnung:')!== -1){newJSON[i]['msgType'] = 'Cancel';}
  15.             for (var o = 0; o < root_key.length; o++) {
  16.                 if (newJSON[i].hasOwnProperty((root_key[o])) == false)  {newJSON[i][(root_key[o])]='';}
  17.             }
  18.             for (var o = 0; o < info_key.length; o++) {
  19.                 if (newJSON[i]['info'][0].hasOwnProperty((info_key[o])) == false)   {newJSON[i]['info'][0][(info_key[o])]='';}
  20.             }
  21.            
  22.             if (newJSON[i]['info'][0].hasOwnProperty('parameter') == false){
  23.                 newJSON[i]['info'][0]['parameter']=[];
  24.             }
  25.    
  26.             while (newJSON[i]['info'][0]['parameter'].length < 2) {
  27.                 newJSON[i]['info'][0]['parameter'].push(test_key);
  28.             }
  29.             if (Array.isArray(newJSON[i]['code']) == true){newJSON[i]['code']=((newJSON[i]['code'])).join(', ')}
  30.             if (Array.isArray(newJSON[i]['info'][0]['category']) == true){newJSON[i]['info'][0]['category']=((newJSON[i]['info'][0]['category'])).join(', ')}
  31.             if (Array.isArray(newJSON[i]['info'][0]['responseType']) == true){newJSON[i]['info'][0]['responseType']=((newJSON[i]['info'][0]['responseType']).join(', '))}
  32.        
  33.             jsonResult = JSON.stringify(newJSON[i]);
  34.            
  35.         }
  36.         }
  37.     }
  38.     return jsonResult;
  39. })(input)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top