Created
January 21, 2019 19:01
-
-
Save PeterBerthelsen/72564cf4b74593d709a5744c3323a440 to your computer and use it in GitHub Desktop.
OrthoBot readingThread function
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) { | |
console.log("Clearing yesterday's IDs"); | |
ss.getRange("OCAreadings!G2:G11").clearContent(); | |
} | |
if (h > 7 && h < 18) { | |
try { | |
var thread = ss.getRange("OCAreadings!F" + (h-6)).getValue(); | |
if (thread) { | |
var response = tweetThread(thread,delim); | |
} else { | |
console.log("No thread found at hour: " + h); | |
console.log("Attempting retweet from hour: " + h-6); | |
var id = ss.getRange("OCAreadings!G" + (h-12)).getValue(); | |
if (id) { | |
reTweet(id); | |
} else { | |
console.log("No valid retweet found!"); | |
} | |
} | |
} catch (e) { | |
console.log("Thread Error: " + e); | |
} | |
if (response) { | |
console.log("First Tweet: " + response); | |
var output = ss.getRange("OCAreadings!G" + (h-6)); | |
output.setValue(response); | |
} | |
} else { | |
console.log("No Thread to tweet. Pending..."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment