Created
November 22, 2016 22:46
-
-
Save ObjectIsAdvantag/62f8cb68e17d7d4ec64bd4c8863bcf00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var csvFile = loadFile("http://hosting.tropo.com/5051540/www/data/numbers.csv"); | |
var numbersToDial = csvJSON(csvFile); | |
for (var i = 0; i<numbersToDial.length-1; i++){ | |
var callee = numbersToDial[i]; | |
call(callee.number, { network: "SMS" }); | |
say("Hi, " + callee.name); | |
hangup(); | |
} | |
//file loading function. | |
function loadFile(url){ | |
var line; | |
var returnFile = ""; | |
connection = new java.net.URL(url).openConnection(); | |
connection.setDoOutput(false); | |
connection.setDoInput(true); | |
connection.setInstanceFollowRedirects(false); | |
connection.setRequestMethod("GET"); | |
connection.setRequestProperty("Content-Type", "text/plain"); | |
connection.setRequestProperty("charset", "utf-8"); | |
connection.connect(); | |
var dis = new java.io.DataInputStream(connection.getInputStream()); | |
while (dis.available() != 0) { | |
line = dis.readLine(); | |
returnFile += line + "#end"; | |
} | |
return returnFile; | |
} | |
function csvJSON(csv){ | |
var lines=csv.split("#end"); | |
var returnJSON = []; | |
var headers=lines[0].split(","); | |
for(var i=1;i<lines.length;i++){ | |
var obj = {}; | |
var currentline=lines[i].split(","); | |
for(var j=0;j<headers.length;j++){ | |
obj[headers[j]] = currentline[j]; | |
} | |
returnJSON.push(obj); | |
} | |
return returnJSON; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment