You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
social-media-poster/Modules/Post-To-Thinkspot.ahk

197 lines
6.4 KiB
Plaintext

; -------------------------------ThinkSpot-------------------------------
PostToThinkSpot:
CurrentSite := "Thinkspot"
if(PostTags = ""){
Message = Skipped: No Post Tags
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
IniWrite, Skipped: No Post Tags, %StatusFileFilePath%, Status, Thinkspot
Return
}
SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile")
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
URLAttempt := NavigateFromBaseURLTo("https://www.thinkspot.com/create/post")
if(URLAttempt = "Failed")
Return
Status := CheckCurrentTabForCurrentSite()
if(Status){
Return
}
Message = Checking Login Status
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
sleep, 1000
try CurrentTabURL := driver.Url
if(InStr(CurrentTabURL, "/sign_in")){
Message = Login Cookies Expired. Trying to Re-Login
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
; SaveDriverURLOFErrorPage()
; Return
Xpath = //input[@name='commit']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=1,SleepLength:=1000)
if(!Status){
Message = Logged in Successfully
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Status := NavigateFromBaseURLTo("https://www.thinkspot.com/create/post")
(Status)?(Return):()
sleep, 2000
}
}
Status := CheckCurrentTabForCurrentSite()
if(Status){
Return
}
/*
Xpath = //a[@href='/create/post']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){
Message = Failed to Click "Create Post" button
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
*/
; CLick into the title box of the new post window
Xpath = //div[@id='editorjs']//div[@class='ql-editor ql-blank']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){
Message = Failed to Click Into Titlebox: Check Login Status
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
sleep, 500
; Input the Post Title
SaveOrPostProgress(Message:="Inputting Post Title",PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = //input[@id='title']
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,SendKeysContent:=PostTitle)
if(Status){
Message = Failed to Input Post Title: Check Login Status
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
; Input post body
if(ImageAttachmentFilepath != "")
PostBody := PostBody . "`n"
SaveOrPostProgress(Message:="Inputting Post Content",PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = //div[@id='editorjs']//p
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,SendKeysContent:=PostBody)
if(Status){
Message = Failed to Input Post Body: Check Login Status
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
; Input Post Tags
Xpath = //span[@role='textbox']
TagsArray := StrSplit(PostTags, ",")
TagsArrayLength := TagsArray.Length() ; Save total number of items in the array
loop, %TagsArrayLength%{
Tag := TagsArray[A_Index]
Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,SendKeysContent:=Tag)
try driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.ENTER)
}
if(ImageAttachmentFilepath != ""){
; Click "Image" button
SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile")
; Insert image by sending it directly.
; elements aren't loaded until the attach image button is pressed though, so defeats the purpose
/*Xpath = //input[@class='ql-image']
try driver.FindElementByXPath(Xpath).SendKeys(ImageAttachmentFilepath)
*/
Xpath = //button[@class='ql-image']
Status := Selenium_LoopToClickXpathAndWaitForOpenWindow(Xpath:=Xpath,NumOfLoops:=10,SleepLength:=1000)
if(Status){
Message = Failed to click "Attach Image" button
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Xpath = //input[@class='ql-image']
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
if(Status){
Message = Failed to Attach Image (E#7611)
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
}
else, {
InputStatus := InputFilePathIntoOpenWindow(ImageAttachmentFilepath)
if(InputStatus = "Failed")
{
sleep, 2000
Xpath = //i[@class='material-icons-outlined'][normalize-space()='image'] ; give it a second try :fingerscrossed:
Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
InputStatus := InputFilePathIntoOpenWindow(ImageAttachmentFilepath)
if(InputStatus)
{ ; Try sending directly to element
Xpath = //input[@class='ql-image']
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
if(Status){
Message = Failed to Attach Image (E#7612)
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
}
}
}
SaveOrPostProgress(Message:="Waiting 10 seconds for Image to finish uploading",PostType:="Tooltip,ErrorLoggingTextFile")
sleep, 10000
}
; Click the Post button
SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = //button[normalize-space()='Post']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){
Message = Failed to Submit Post
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
IniWrite, Successful, %StatusFileFilePath%, Status, Thinkspot
AddToTotalPostsPostedCount()
PauseBetweenPosts()
; dismiss the pop up that appears for some reason
; try driver.switchToalert().accept()
DevModeMsgBox("done!")
Message = Post Publish Successful
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Return
; -------------------------------/ThinkSpot-------------------------------