Subversion Repositories HomeAutomation

Rev

Rev 1506 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. function OnlinePhonebook(callback)
  3. {
  4.     this.myHTTP = new HTTP();
  5.     this.myCallback = callback;
  6. }
  7.  
  8. OnlinePhonebook.prototype.myHTTP = null;
  9. OnlinePhonebook.prototype.myCallback = null;
  10. OnlinePhonebook.prototype.myPhonenumber;
  11.  
  12. OnlinePhonebook.prototype.lookup = function(phonenumber)
  13. {
  14.     var self = this;
  15.  
  16.     this.myPhonenumber = phonenumber;
  17.  
  18.     this.myHTTP.request(function(result, header, content) { self.httpCallback(result, header, content); }, "wap.hitta.se/default.aspx?Who=" + phonenumber + "&Where=&PageAction=White");
  19. }
  20.  
  21. OnlinePhonebook.prototype.httpCallback = function(result, header, content)
  22. {
  23.     var persons = new Array();
  24.  
  25.     if (result.indexOf("200 OK") != -1)
  26.     {
  27.         var endString = "<anchor>Tillbaka<prev/></anchor>";
  28.         var nameStartString = " title=\"Link\">";
  29.         var nameEndString = "</a>";
  30.    
  31.         var lines = content.split("<br/>");
  32.        
  33.         for (var n = 1; n < lines.length; n++)
  34.         {
  35.             var line = lines[n].trim(" \n");
  36.            
  37.             if (line.indexOf(endString) != -1)
  38.             {
  39.                 break;
  40.             }
  41.        
  42.             var pos = line.indexOf(nameStartString + (persons.length+1) + ".");
  43.            
  44.             if (pos != -1)
  45.             {
  46.                 pos += nameStartString.length + 2
  47.                 persons[persons.length] = line.substr(pos, line.length-pos-nameEndString.length).html_entity_decode().replace("  ", " ");
  48.             }
  49.         }
  50.     }
  51.     else
  52.     {
  53.         log("OnlinePhonebook: Failed to do name lookup, result was: " + result + "\n");
  54.     }
  55. /* Uncomment to enable output to file
  56.     // Update main dtmf menu
  57.     var date = new Date();
  58.     // Get the current date time on the format YYYY-mm-dd HH.ii.ss
  59.     var dateAndTime = date.getDateTimeFormated();
  60.     var filename = "/dev/shm/can/lastPhoneCall";
  61.     var content = getFileContents(filename);
  62.     if (!content) {
  63.         content = "";
  64.     }
  65.     content += dateAndTime +": ";
  66.     content += this.myPhonenumber+"\t";
  67.     var i = 0;
  68.     var separator = "";
  69.     while (persons[i] != null) {
  70.         content += separator + persons[i];
  71.         i++;
  72.         separator = ", ";
  73.     }
  74.    
  75.     content += "\n";
  76.     var filename = "/dev/shm/can/lastPhoneCall";
  77.     setFileContents(filename, content);
  78. */
  79.     this.myCallback(this.myPhonenumber, persons);
  80. }
  81.