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
function readingThread(){ | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); //Spreadsheet | |
var d = new Date(); //set date | |
var h = d.getHours(); //set hour | |
var m = d.getMinutes(); //set minutes | |
var delim = "|"; | |
console.log("initiating readingThread"); | |
console.log("Hour defined: " + h); | |
console.log("Minute defined: " + m); | |
if (h < 2) { |
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
function tweetThread(stringToTweet,delim,img,r){ //pass a string variable with additional option to parse (used for bookending tweets) | |
//////////////////////////Variables//////////////////////////////////////////////////////// | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); //spreadsheet | |
var twtMax = 280; //Character limit for Twitter (variable in case it changes) | |
var tweets = new Array(0); //create final array to populate with tweets | |
var total = ""; //variable for 'total' tweet-length section if parsing is required | |
var start = 0; //starting character for .substring() function, default 0 | |
var excess = 0; |
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
//////////////////////////Output/////////////////////////////////////////////////////////// | |
if (r) { | |
var replyTo = r | |
} else { | |
var replyTo = 0; //set reply (each tweet will reply to previous, first will be null | |
} | |
for (i in tweets){ //for each tweet in thread... | |
console.log("Tweet Attempt: " + i); //log attempt number (starting @ 0) | |
try{ | |
if (imgs[i]) { //if valid image URL exists... |
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
//////////////////////////Split Images///////////////////////////////////////////////////// | |
if (img){ //if image string has been passed... | |
var imgs = img.split(","); //split CSV into individual URLs | |
console.log(img + " contains " + imgs.length + " values!"); //log number of images found | |
} else { //if no image string has been passed... | |
console.log("No images passed through threading function"); //log no images | |
} //end image processing |
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
//////////////////////////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: " + | |
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
//////////////////////////Length Check///////////////////////////////////////////////////// | |
try { //Attempt to check string value for parsing needs | |
if (stringToTweet == undefined) {throw "Undefined Value: 'stringToTweet'"}; //thrown when tweet string is undefined | |
var thread = stringToTweet.split(delim); //split initial string along provided delimeter | |
console.log("Input Thread Length: " + thread.length); //log number of strings in thread | |
} catch(e) { //Catch thrown error | |
console.log("Cannot Split Thread. Error: " + e); //Log error | |
} | |
try { //attempt to evaluate parsed tweet thread | |
if (thread == undefined) {throw "Undefined Value: |
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
function tweetThread(stringToTweet,delim,img,r){ //pass a string variable with additional option to parse (used for bookending tweets) | |
//////////////////////////Variables//////////////////////////////////////////////////////// | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); //spreadsheet | |
var twtMax = 280; //Character limit for Twitter (variable in case it changes) | |
var tweets = new Array(0); //create final array to populate with tweets | |
var total = ""; //variable for 'total' tweet-length section if parsing is required | |
var start = 0; //starting character for .substring() function, default 0 | |
var excess = 0; |
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
function sendTweet(TweetText, IdInResponseTo, ImageAttachURL){ | |
//////////////////////////Set Variables/////////////////////////////////////////////////////// | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); //spreadsheet | |
var logsheet = ss.getSheetByName("TweetLog"); | |
var lastRow = Math.max(logsheet.getLastRow(),1) + 1; | |
var twitterKeys= { //Twitter Authentication Tokens to pass through props | |
TWITTER_CONSUMER_KEY: "[YOUR VALUE HERE]", | |
TWITTER_CONSUMER_SECRET: "[YOUR VALUE HERE]", | |
TWITTER_ACCESS_TOKEN: "[YOUR VALUE HERE]", | |
TWITTER_ACCESS_SECRET: "[YOUR VALUE HERE]" |
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
//////////////////////////Send Tweet & Process Response/////////////////////////////////////// | |
try{ //attempt to send tweet | |
var response = service.sendTweet(status, params); //enter status & params, return response | |
if (response) { //If response is detected... | |
console.log("Posted Tweet ID: " + response.id_str); //log response | |
try { //attempt to log... | |
logsheet.insertRowBefore(2); //insert row for logs | |
logsheet.getRange(2,1).setValue(Date()); //timestamp | |
logsheet.getRange(2,2).setValue(response.id_str); //tweet id | |
logshe |
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
//////////////////////////Upload Images/////////////////////////////////////////////////////// | |
if (ImageAttachURL == 0 || ImageAttachURL == null){ //If no image URLs are listed... | |
console.log("No images detected!"); //Log no images detected | |
} else { //If image URLs are listed... | |
try{ //Attempt to upload images from URLs | |
var mediaId = new Array(0); //IDs for uploads, will be CSVs | |
var imgs = ImageAttachURL.split(","); //Split URL string into individual links | |
console.log(imgs.length + " images detected!"); //Log num |
NewerOlder