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-Locals.ahk

163 lines
5.2 KiB
Plaintext

; -------------------------------Locals-------------------------------
PostToLocals:
CurrentSite := "Locals"
; DevModeMsgBox("clik ok to continue")
; @todo: Add auto-login to locals
SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
IniRead, LocalsURL, %SettingsIniFilepath%, %ScriptSettingsSection%, LocalsURL, %A_Space%
if(LocalsURL = ""){
Message = Please add your Locals Profile URL to the settings.ini file under`n`n[General]`nLocalsURL=
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
Message = LocalsURL from Ini File: %LocalsURL%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
if(!InStr(LocalsURL, "/share/post")){
LocalsURL = https://freedomain.locals.com/share/post
Message = LocalsURL from ini file was incorrect. New URL set to %LocalsURL% and saved to settings.ini
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
IniWrite, %LocalsURL%, %SettingsIniFilepath%, %ScriptSettingsSection%, LocalsURL
}
; LocalsURL := StrReplace(Localsurl, "/share/post", "")
; LocalsURL := Localsurl . "/login"
; Message = Localsurl: %LocalsURL%
; SaveOrPostProgress(Message:=Message,PostType:=",DiscordErrorLogging")
Status := NavigateFromBaseURLTo(LocalsURL)
if(Status = "Failed")
Return
Status := CheckCurrentTabForCurrentSite()
if(Status){
Return
}
sleep, 1000
Message = Checking Login Status
try CurrentTabURL := driver.Url
if(InStr(CurrentTabURL, "/login") OR InStr(CurrentTabURL, "/register")){
Message = Login Expired. Please log back in
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
Message = Inputting Post Content
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = //*[@id="body"]
try driver.FindElementByXPath(Xpath).click()
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
if(Status){
Message = Failed to input Title
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
if(ImageAttachmentFilepath != ""){
; Click the upload image button
SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = //input[@multiple='multiple']
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
if(Status){
Message = Failed to Upload Image
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
; driver.FindElementByXPath(Xpath).SendKeys(ImageAttachmentFilepath)
; driver.FindElementByXPath(Xpath).SendKeys(ImageAttachmentFilepath)
SaveOrPostProgress(Message:="Waiting 10 seconds for Image to finish uploading",PostType:="Tooltip,ErrorLoggingTextFile")
sleep, 10000
}
Message = Submitting Post
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
/* ; Click the final "post" button
SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")
Status := Selenium_LoopToClickName(ElementName:="submitPost",NumOfLoops:=5,SleepLength:=1000)
if(Status){
Message = Failed to Submit Post
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
*/
; msgbox
; @todo: add error check into here to check the current page url and after page url
; Click Publish post
js = document.getElementsByName('submitPost')[0].click(); ; Send content through javascript (Great for getting around emoji chrome limitaitons)
try driver.executeScript(js)
Message = Double checking that post got submitted
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
sleep, 5000
try CurrentTabURL := driver.Url
if(InStr(CurrentTabURL, "share/post")) { ; post failed to submit if it's still on the create new post page
Message = Error: Post Was Input but Failed to Submit.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
/* ; Double check that post got submitted
js = return document.querySelector("#body").value
Status := driver.executeScript(js)
if(Status != ""){
Message = Error: Post Failed to Submit for some reason
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
*/
IniWrite, Successful, %StatusFileFilePath%, Status, Locals
AddToTotalPostsPostedCount()
SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
PauseBetweenPosts()
DevModeMsgBox("done!")
Message = Post Publish Successful
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Return
; -------------------------------/Locals-------------------------------