Skip to content

Instantly share code, notes, and snippets.

@PeterBerthelsen
Created January 21, 2019 16:49
Show Gist options
  • Save PeterBerthelsen/f1700cb249d9ae5b78c4348f5bc127c0 to your computer and use it in GitHub Desktop.
Save PeterBerthelsen/f1700cb249d9ae5b78c4348f5bc127c0 to your computer and use it in GitHub Desktop.
OrthoThread Parsing
//////////////////////////Parsing Loop/////////////////////////////////////////////////////
while (start<thread[i].length) { //As long as the starting position is NOT at the end of thread[i]...
total = thread[i].substring(start,start + twtMax); //full length of tweet
excess = total.length - total.lastIndexOf(" "); //amount of characters to cut off of 'total' to get to a space (end of last full word)
parsed = thread[i].substring(start,start + twtMax - excess); //new text of tweet-length string ending in full word
start = start + parsed.length + 1; //new start position is the first character after finished tweet
tweets.push(parsed); //adds tweet to thread
console.log("Parsed new tweet," + " length: " +
parsed.length +
" | Tweetable! Adding to tweet thread"); //log parse length, success
console.log("Tweet Added: " + parsed);
} //end parsing loop
console.log("Parsing Complete"); //log parsing complete
} else { //if thread[i] is tweet length...
console.log("Tweetable! Adding to tweet thread"); //log length
tweets.push(thread[i]) //add thread[i] to tweets
console.log("Tweet Added: " + thread[i]);
console.log("Tweet Thread length: " + tweets.length);
}
} //end loop
} catch (e) { //Catch thrown error
console.log("Parsing Error. Error: " + e); //Log error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment