added check for Chrome dialog boxes on each Tab url navigation

main
Yuriy 2 years ago
parent 65ed1f7a8c
commit 2813ca7856

@ -1126,6 +1126,250 @@ Return
*/ */
; -------------------------------Discord-------------------------------
PostToDiscord:
CurrentSite := "Discord"
; SaveOrPostProgress(Message:="Posting through API",PostType:="Tooltip,ErrorLoggingTextFile")
Message = Posting Through API
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
if(DiscordParlerWebhookURL = ""){
Message = Webhook Link not found. Please set "DiscordParlerWebhookURL" in %SettingsIniFilepath%.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
if(BoldTitleWAPI){
if(NewLineBetweenTitle)
Message = **%PostTitle%**`n`n%PostBody%
else,
Message = **%PostTitle%**`n%PostBody%
}
else, { ; NOT bold title
if(NewLineBetweenTitle)
Message = %PostTitle%`n`n%PostBody%
else,
Message = %PostTitle%`n%PostBody%
}
if(ImageAttachmentFilepath != ""){
SingleQuotationMark = "
; remove any single quotes from filepath
ImageAttachmentFilepath := StrReplace(ImageAttachmentFilepath, SingleQuotationMark, "")
if(StrLen(Message) > 1999){ ; split message into two parts if longer than this
loop % StrLen(Message) {
if(A_index < 1900)
Continue
SplitCharNumber := A_index
; IndexMinusOne := A_index - 1
SplitLocationText := SubStr(Message, SplitCharNumber, 1)
if(SplitLocationText = " "){
Break
; Msgbox % "SplitLocation: " SplitLocation
}
}
DiscordMessagePartOne := SubStr(Message, 1, SplitCharNumber)
SplitCharNumber := SplitCharNumber + 1
DiscordMessagePartTwo := SubStr(Message, SplitCharNumber)
; Msgbox % "DiscordMessagePartOne: " DiscordMessagePartOne
; Msgbox % "DiscordMessagePartTwo: " DiscordMessagePartTwo
Status := SaveOrPostProgress(Message:=DiscordMessagePartOne,PostType:="ErrorLoggingTextFile,DiscordParler")
Status := SaveOrPostProgress(Message:=DiscordMessagePartTwo,PostType:="ErrorLoggingTextFile,DiscordParler")
Status := UploadImageToDiscord(DiscordParlerWebhookURL, "", ImageAttachmentFilepath)
; Msgbox % "StatusOne: " StatusOne
; Msgbox % "StatusTwo: " StatusTwo
/* if(!InStr(StatusOne, "id")){ ; if error for each of the messages, post its
parsed := JSON.Load(StatusOne)
StatusOneFailure := parsed.content[1]
parsed := JSON.Load(StatusTwo)
StatusTwoFailure := parsed.content[1]
Message = Partial Failure for the following reason: %StatusOneFailure% OR %StatusTwoFailure%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
}
*/
} ; end of strlen > 1999
else, {
Status := UploadImageToDiscord(DiscordParlerWebhookURL, Message, ImageAttachmentFilepath)
SaveOrPostProgress(Message:="Status",PostType:="ErrorLoggingTextFile")
if(!InStr(Status, "id")){
parsed := JSON.Load(Status)
Error := parsed.content[1]
; Msgbox % "error: " error
Message = Discord Post Failed due to API Issue. Error was saved to errorlog; please forward to Yuriy
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
}
}
else {
if(StrLen(Message) > 1999){ ; split message into two parts if longer than this
loop % StrLen(Message) {
if(A_index < 1900)
Continue
SplitCharNumber := A_index
SplitLocationText := SubStr(Message, SplitCharNumber, 1)
if(SplitLocationText = " "){
Break
}
}
DiscordMessagePartOne := SubStr(Message, 1, SplitCharNumber)
SplitCharNumber := SplitCharNumber + 1
DiscordMessagePartTwo := SubStr(Message, SplitCharNumber)
Status := SaveOrPostProgress(Message:=DiscordMessagePartOne,PostType:="ErrorLoggingTextFile,DiscordParler")
Status := SaveOrPostProgress(Message:=DiscordMessagePartTwo,PostType:="ErrorLoggingTextFile,DiscordParler")
}
else,
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordParler")
}
IniWrite, Successful, %StatusFileFilePath%, Status, Discord
AddToTotalPostsPostedCount()
Message = Submitted Successfully
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Return
; -------------------------------/Discord-------------------------------
/*
*/
; -------------------------------Telegram-------------------------------
; API documentation
; https://core.telegram.org/bots/api#sendmessage
PostToTelegram:
CurrentSite := "Telegram"
; SaveOrPostProgress(Message:="Posting through API",PostType:="Tooltip,ErrorLoggingTextFile")
Message = Posting Through API
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
if(TelegramBotToken = "" Or TelegramBotChatID =""){
Message = TelegramBotToken or TelegramBotChatID is missing from %SettingsIniFilepath%. `nPlease input them and rerun the script.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
; Msgbox, 4096, Error!, TelegramBotToken or TelegramBotChatID is missing from %SettingsIniFilepath%. `nPlease input them and rerun the script.
Return
}
LineBreakChar = `%0A ; Used for API
TelegramTitle := ASCIISTRReplace(PostTitle)
TelegramBody := ASCIISTRReplace(PostBody)
/* TelegramTitle := PostTitle
TelegramBody := PostBody
*/
; Msgbox % "TelegramBody: " TelegramBody
if(PostBody = ""){
if(BoldTitleWAPI)
Message := "*" . TelegramTitle . "*"
else,
Message := TelegramTitle
}
else, { ; if postbody is not blank
; MsgBox, we in post body
if(BoldTitleWAPI){
if(NewLineBetweenTitle)
Message := "*" . TelegramTitle . "*" . "`n`n" . TelegramBody
else,
Message := "*" . TelegramTitle . "*" . "`n" . TelegramBody
}
else, { ; NOT Bold Title
if(NewLineBetweenTitle)
Message := TelegramTitle . "`n`n" . TelegramBody
else,
Message := TelegramTitle . "`n" . TelegramBody
}
}
; Msgbox % "Message: " Message
; REMOVE
; Message := PostTitle . "`n" . PostBody
; Msgbox % "TelegramTitle: " TelegramTitle
; Msgbox % "TelegramBody: " TelegramBody
; Msgbox % "Message: " Message
if(ImageAttachmentFilepath != "" AND StrLen(Message) > 1020){ ; utilize function that converts image to MIME/multi form
; Telegram API character limit of 4096 for a basic message.
; @todo: add functionality to split messages longer than 4096 characters
; msgbox, 2
if(BoldTitleWAPI)
TelegramTitle := "*" . TelegramTitle . "*"
else,
TelegramTitle := TelegramTitle
Status := SendTelegramPhoto(TelegramBotToken, TelegramBotChatID, ImageAttachmentFilepath, caption := TelegramTitle ) ; you could add more options; compare the Telegram API docs
Status := SendTelegramMessage(TelegramBotToken, TelegramBotChatID, text := TelegramBody )
}
else if(ImageAttachmentFilepath != "" AND StrLen(Message) <= 1020){
Status := SendTelegramPhoto(TelegramBotToken, TelegramBotChatID, ImageAttachmentFilepath, caption := Message ) ; you could add more options; compare the Telegram API docs
}
else,
{ ; send just the text
; Msgbox % "Message: " Message
Status := SendTelegramMessage(TelegramBotToken, TelegramBotChatID, text := Message )
}
if(Status){
Message = Upload Failed due to API issue. Telegram API Returned Value:`n %Status%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
; SaveOrPostProgress(Message:=Message,PostType:=",ErrorLoggingTextFile,DiscordParler")
IniWrite, Successful, %StatusFileFilePath%, Status, Telegram
AddToTotalPostsPostedCount()
Message = Submitted Successfully
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Return
; -------------------------------/Telegram-------------------------------
/*
*/
;---------------Facebook---------------------------------- ;---------------Facebook----------------------------------
PostToFacebook: PostToFacebook:
CurrentSite := "Facebook" CurrentSite := "Facebook"
@ -1337,7 +1581,6 @@ if(Status){
Return Return
} }
; Check login status by checking the header of the page for "Feed" text ; Check login status by checking the header of the page for "Feed" text
loop, 5 { loop, 5 {
SaveOrPostProgress(Message:="Checking Login Status",PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:="Checking Login Status",PostType:="Tooltip,ErrorLoggingTextFile")
@ -1362,42 +1605,9 @@ if(!InStr(status, "Feed")){
} }
/*try CurrentTabURL := driver.Url
; Msgbox % "CurrentTabURL: " CurrentTabURL
if(InStr(CurrentTabURL, "/login")){
SaveOrPostProgress(Message:="Cookies Expired. Trying to Log back in",PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Xpath = //div[@class='form__contain']//button[@class='button'][normalize-space()='Log In']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
if(Status){
SaveOrPostProgress(Message:="Failed to click login button",PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
}
sleep, 1000
}
*/
; Message = Trying to click on "Parley.." to start new post
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
; sleep, 5000 ; sleep 2 seconds for page to fully load in case it's being slow
; js = document.getElementsByClassName('input-trigger')[0].click()
; try driver.executeScript(JS) ;Execute Javascript
/* ; if failed to click into box then error out
if(Status){
Message = Post Failed: Page didn't load properly
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
*/
; Msgbox % "Status: " Status
Message = Inputting Post Message = Inputting Post
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
/* ; click into popup box /* ; click into popup box
xpath = //div[@placeholder='Parley...'] xpath = //div[@placeholder='Parley...']
@ -1438,43 +1648,6 @@ if(InStr(CurrentTabURL, "/login")){
Return Return
} }
; driver.FindElementByXPath(Xpath).SendKeys("heyyyy")
/* ; Input Post content pop up
Xpath = //div[@id='create-parley-wysiwyg']
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
if(Status){
Message = Failed to input Post Message with relative Xpath
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; Input post with JS
JsToExecute = document.querySelector("#create-parley-wysiwyg").innerText = '%JSPostTitleAndBody%'
try Status := driver.executeScript(JsToExecute)
; Check if text got input
JsToExecute = return document.querySelector("#create-parley-wysiwyg").innerText
try Status := driver.executeScript(JsToExecute)
if(Status = ""){
Message = Failed to Input with JS as well
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Xpath = /html[1]/body[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[3]/div[1]/div[2]/div[1]/div[1]/form[1]/div[1]/div[2]/div[1]
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
if(Status){
try CurrentTab := driver.url
Message = Failed to input Post: `nCurrent Tab URL: %CurrentTab%
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
}
}
*/
if(ImageAttachmentFilepath != ""){ if(ImageAttachmentFilepath != ""){
Message = Attaching Image Message = Attaching Image
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
@ -1510,43 +1683,6 @@ if(InStr(CurrentTabURL, "/login")){
Return Return
} }
/* Message = Waiting 5 seconds to double check that the post got submitted
SaveOrPostProgress(Message:=Message,PostType:="Tooltip, ErrorLoggingTextFile")
sleep, 5000
; check the text contents of the input box to make sure that the post got submitted
JsToExecute = return document.querySelector("div[id='create-parley-wysiwyg'] div").textContent;
try Status := driver.executeScript(JsToExecute)
if(Status != ""){
Xpath = //button[@id='submit-button'] ; click the submit button again
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
; Message = Post got input but did not submit properly and still present after 5 seconds`nPost Content: %Status%
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
}
*/
; DevModeMsgBox(Status)
/* js = document.getElementById('submit-button').click();
status := JS_TryToExecute(js,2,2000)
*/
/* sleep, 3000
jscheck = return document.getElementsByClassName('emoji-wysiwyg-editor')[0].textContent;
try Status := driver.executeScript(jsCheck)
if(Status != ""){
Message = Failed to Submit Post (#2523)
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
*/
; Msgbox % "Status: " Status
IniWrite, Successful, %StatusFileFilePath%, Status, Parler IniWrite, Successful, %StatusFileFilePath%, Status, Parler
@ -1562,283 +1698,147 @@ if(InStr(CurrentTabURL, "/login")){
Return Return
; -------------------------------/Parler------------------------------- ; -------------------------------/Parler-------------------------------
/*
*/
; -------------------------------SubScribeStar-------------------------------
PostToSubscribeStar:
CurrentSite := "SubScribeStar"
IniRead, SubscribeStarProfileURL, %SettingsIniFilepath%, SocialMediaPoster, SubscribeStarProfileURL, %A_Space%
if(SubscribeStarProfileURL = ""){
Message = SubscribeStarProfileURL is blank. Please update Settings.ini
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; -------------------------------Discord-------------------------------
PostToDiscord:
CurrentSite := "Discord"
; SaveOrPostProgress(Message:="Posting through API",PostType:="Tooltip,ErrorLoggingTextFile") Status := NavigateFromBaseURLTo(SubscribeStarProfileURL)
Message = Posting Through API if(Status){
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") Message = Failed to Navigate to SubScribeStar Page
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
}
if(DiscordParlerWebhookURL = ""){ Status := CheckCurrentTabForCurrentSite()
Message = Webhook Link not found. Please set "DiscordParlerWebhookURL" in %SettingsIniFilepath%. if(Status){
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") Return
Return }
}
if(BoldTitleWAPI){
if(NewLineBetweenTitle)
Message = **%PostTitle%**`n`n%PostBody%
else,
Message = **%PostTitle%**`n%PostBody%
}
else, { ; NOT bold title
if(NewLineBetweenTitle)
Message = %PostTitle%`n`n%PostBody%
else,
Message = %PostTitle%`n%PostBody%
}
/*
if(PostTitle != "")
Message = **%PostTitle%**`n%PostBody%
else,
Message = %PostBody%
*/
if(ImageAttachmentFilepath != ""){
SingleQuotationMark = "
; remove any single quotes from filepath
ImageAttachmentFilepath := StrReplace(ImageAttachmentFilepath, SingleQuotationMark, "")
if(StrLen(Message) > 1999){ ; split message into two parts if longer than this
loop % StrLen(Message) {
if(A_index < 1900)
Continue
SplitCharNumber := A_index
; IndexMinusOne := A_index - 1
SplitLocationText := SubStr(Message, SplitCharNumber, 1)
if(SplitLocationText = " "){
Break
; Msgbox % "SplitLocation: " SplitLocation
}
}
DiscordMessagePartOne := SubStr(Message, 1, SplitCharNumber)
SplitCharNumber := SplitCharNumber + 1
DiscordMessagePartTwo := SubStr(Message, SplitCharNumber)
; Msgbox % "DiscordMessagePartOne: " DiscordMessagePartOne
; Msgbox % "DiscordMessagePartTwo: " DiscordMessagePartTwo
Status := SaveOrPostProgress(Message:=DiscordMessagePartOne,PostType:="ErrorLoggingTextFile,DiscordParler")
Status := SaveOrPostProgress(Message:=DiscordMessagePartTwo,PostType:="ErrorLoggingTextFile,DiscordParler")
Status := UploadImageToDiscord(DiscordParlerWebhookURL, "", ImageAttachmentFilepath)
; Msgbox % "StatusOne: " StatusOne
; Msgbox % "StatusTwo: " StatusTwo
/* if(!InStr(StatusOne, "id")){ ; if error for each of the messages, post its
parsed := JSON.Load(StatusOne)
StatusOneFailure := parsed.content[1]
parsed := JSON.Load(StatusTwo)
StatusTwoFailure := parsed.content[1]
Message = Partial Failure for the following reason: %StatusOneFailure% OR %StatusTwoFailure% Message = Checking Login Status
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
}
*/
} ; end of strlen > 1999
else, {
Status := UploadImageToDiscord(DiscordParlerWebhookURL, Message, ImageAttachmentFilepath)
SaveOrPostProgress(Message:="Status",PostType:="ErrorLoggingTextFile")
if(!InStr(Status, "id")){ ; check for Log In button text
parsed := JSON.Load(Status) js = return document.querySelector(".top_bar-login.is-button").innerText;
Error := parsed.content[1] try LoginStatus := driver.executeScript(js)
; Msgbox % "error: " error
Message = Discord Post Failed due to API Issue. Error was saved to errorlog; please forward to Yuriy
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
}
}
else {
if(StrLen(Message) > 1999){ ; split message into two parts if longer than this
loop % StrLen(Message) {
if(A_index < 1900) if(InStr(LoginStatus, "Log In")){ ; need to log in
Continue SaveOrPostProgress(Message:="Navigating to login page",PostType:="Tooltip,ErrorLoggingTextFile")
SplitCharNumber := A_index try driver.Get("https://www.subscribestar.com/login") ; navigate to login page
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
SplitLocationText := SubStr(Message, SplitCharNumber, 1) if(AutoLogin){
if(SplitLocationText = " "){
Break
}
}
DiscordMessagePartOne := SubStr(Message, 1, SplitCharNumber) ; Check if email box contains text inputted by chrome
SplitCharNumber := SplitCharNumber + 1 js = return document.querySelector("input[placeholder='your email']").value;
DiscordMessagePartTwo := SubStr(Message, SplitCharNumber) status := driver.executeScript(js)
if(StrLen(Status) > 0){ ; click enter on the email input field
Xpath = //input[@placeholder='your email']
driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.ENTER)
Status := SaveOrPostProgress(Message:=DiscordMessagePartOne,PostType:="ErrorLoggingTextFile,DiscordParler") driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
Status := SaveOrPostProgress(Message:=DiscordMessagePartTwo,PostType:="ErrorLoggingTextFile,DiscordParler")
} }
else,
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordParler")
} }
else, {
IniWrite, Successful, %StatusFileFilePath%, Status, Discord SaveOrPostProgress(Message:="Login Expired. Please log back in",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
AddToTotalPostsPostedCount() SaveDriverURLOFErrorPage()
Message = Submitted Successfully
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Return
; -------------------------------/Discord-------------------------------
; -------------------------------SubScribeStar-------------------------------
PostToSubscribeStar:
CurrentSite := "SubScribeStar"
IniRead, SubscribeStarProfileURL, %SettingsIniFilepath%, SocialMediaPoster, SubscribeStarProfileURL, %A_Space%
if(SubscribeStarProfileURL = ""){
Message = SubscribeStarProfileURL is blank. Please update Settings.ini
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return Return
} }
}
SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Message = Inputting Post
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
Status := NavigateFromBaseURLTo(SubscribeStarProfileURL) ; Click on "Start your post by clicking here"
if(Status){ Xpath = //div[contains(text(),'Create Post')]
Message = Failed to Navigate to SubScribeStar Page Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") if(Status){
} Message = Failed to Click "Create Post" button with relative xpath
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Status := CheckCurrentTabForCurrentSite() Xpath = //div[@class='new_post']//div[@class='new_post-create_button']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
if(Status){ if(Status){
Return Message = Failed to click "Create Post" button with Contains(Text) xpath and relative Xpath - Trying wtih ID
} SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Message = Checking Login Status
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
; check for Log In button text
js = return document.querySelector(".top_bar-login.is-button").innerText;
try LoginStatus := driver.executeScript(js)
if(InStr(LoginStatus, "Log In")){ ; need to log in
SaveOrPostProgress(Message:="Navigating to login page",PostType:="Tooltip,ErrorLoggingTextFile")
try driver.Get("https://www.subscribestar.com/login") ; navigate to login page
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
if(AutoLogin){
; Check if email box contains text inputted by chrome
js = return document.querySelector("input[placeholder='your email']").value;
status := driver.executeScript(js)
if(StrLen(Status) > 0){ ; click enter on the email input field
Xpath = //input[@placeholder='your email']
driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.ENTER)
driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding Status := Selenium_LoopToClickID(IDName:="cover_upload",NumOfLoops:=5,SleepLength:=1000)
} if(Status){
} Message = Login Expired. Please log back in
else, { SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveOrPostProgress(Message:="Login Expired. Please log back in",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage() SaveDriverURLOFErrorPage()
Return Return
} }
} }
}
; sleep, 5000
; msgbox
Message = Inputting Post ; Clear any previous content from the post box
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") Message = Clearing if any text exists from an unposted post
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
; Click on "Start your post by clicking here"
Xpath = //div[contains(text(),'Create Post')]
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){
Message = Failed to Click "Create Post" button with relative xpath
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Xpath = //div[@class='new_post']//div[@class='new_post-create_button']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
if(Status){
Message = Failed to click "Create Post" button with Contains(Text) xpath and relative Xpath - Trying wtih ID
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Status := Selenium_LoopToClickID(IDName:="cover_upload",NumOfLoops:=5,SleepLength:=1000)
if(Status){
Message = Login Expired. Please log back in
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
}
}
; sleep, 5000
; msgbox
; Clear any previous content from the post box Xpath = //trix-editor[@role='textbox']
Message = Clearing if any text exists from an unposted post Status := Selenium_LoopToClearXpath(Xpath,NumOfLoops:=5,SleepLength:=1000)
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") if(Status){
}
; try driver.FindElementByXPath(Xpath).clear() ;Clears content from an element and sets
Xpath = //trix-editor[@role='textbox']
Status := Selenium_LoopToClearXpath(Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){
}
; try driver.FindElementByXPath(Xpath).clear() ;Clears content from an element and sets
; Input Text into pop-up edit box
SaveOrPostProgress(Message:="Inputting Post Content",PostType:="Tooltip,ErrorLoggingTextFile")
; Input Text into pop-up edit box Xpath = //trix-editor[@role='textbox']
SaveOrPostProgress(Message:="Inputting Post Content",PostType:="Tooltip,ErrorLoggingTextFile") Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
if(Status){
Message = Failed to Input Post using Direct Xpath. Trying with Relative
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Xpath = //trix-editor[@role='textbox'] Xpath = /html/body/div/div[3]/div[2]/div[2]/div/div[1]/form/div[2]/div[1]/trix-editor
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostTitleAndBody) Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
if(Status){ if(Status){
Message = Failed to Input Post using Direct Xpath. Trying with Relative Message = Failed to Input Post using Relative Xpath. Trying with Javascript
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Xpath = /html/body/div/div[3]/div[2]/div[2]/div/div[1]/form/div[2]/div[1]/trix-editor
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,StringTextContent:=PostTitleAndBody)
if(Status){
Message = Failed to Input Post using Relative Xpath. Trying with Javascript
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
SubscribeStarJSDescription := FormatTextToJSText(PostTitleAndBody)
SubscribeStarJSDescription := FormatTextToJSText(PostTitleAndBody) js = document.querySelector("trix-editor[role='textbox']").value = "%SubscribeStarJSDescription%";
js = document.querySelector("trix-editor[role='textbox']").value = "%SubscribeStarJSDescription%"; try driver.executeScript(js) ;Executes a Javascript on the webpage, mostly used for buttons.
try driver.executeScript(js) ;Executes a Javascript on the webpage, mostly used for buttons. catch e {
catch e { Message = Failed to Input Post Contents (E#8281)
Message = Failed to Input Post Contents (E#8281) SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") SaveDriverURLOFErrorPage()
SaveDriverURLOFErrorPage() Return
Return
}
; msgbox, 3
} }
; msgbox, 3
}
} }
; Attach an image if a filepath was provided ; Attach an image if a filepath was provided
if(ImageAttachmentFilepath != ""){ if(ImageAttachmentFilepath != ""){
SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile")
; this works for both images and videos ; this works for both images and videos
Xpath = //input[@multiple='multiple'] Xpath = //input[@multiple='multiple']
driver.FindElementByXPath(Xpath).SendKeys(ImageAttachmentFilepath) driver.FindElementByXPath(Xpath).SendKeys(ImageAttachmentFilepath)
/* Xpath = //span[@class='trix-button-group trix-upload-buttons']//button[2] /* Xpath = //span[@class='trix-button-group trix-upload-buttons']//button[2]
@ -1887,113 +1887,6 @@ if(InStr(CurrentTabURL, "/login")){
Return Return
; -------------------------------/SubScribeStar------------------------------- ; -------------------------------/SubScribeStar-------------------------------
; -------------------------------Telegram-------------------------------
; API documentation
; https://core.telegram.org/bots/api#sendmessage
PostToTelegram:
CurrentSite := "Telegram"
; SaveOrPostProgress(Message:="Posting through API",PostType:="Tooltip,ErrorLoggingTextFile")
Message = Posting Through API
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
if(TelegramBotToken = "" Or TelegramBotChatID =""){
Message = TelegramBotToken or TelegramBotChatID is missing from %SettingsIniFilepath%. `nPlease input them and rerun the script.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
; Msgbox, 4096, Error!, TelegramBotToken or TelegramBotChatID is missing from %SettingsIniFilepath%. `nPlease input them and rerun the script.
Return
}
LineBreakChar = `%0A ; Used for API
TelegramTitle := ASCIISTRReplace(PostTitle)
TelegramBody := ASCIISTRReplace(PostBody)
/* TelegramTitle := PostTitle
TelegramBody := PostBody
*/
; Msgbox % "TelegramBody: " TelegramBody
if(PostBody = ""){
if(BoldTitleWAPI)
Message := "*" . TelegramTitle . "*"
else,
Message := TelegramTitle
}
else, { ; if postbody is not blank
; MsgBox, we in post body
if(BoldTitleWAPI){
if(NewLineBetweenTitle)
Message := "*" . TelegramTitle . "*" . "`n`n" . TelegramBody
else,
Message := "*" . TelegramTitle . "*" . "`n" . TelegramBody
}
else, { ; NOT Bold Title
if(NewLineBetweenTitle)
Message := TelegramTitle . "`n`n" . TelegramBody
else,
Message := TelegramTitle . "`n" . TelegramBody
}
}
; Msgbox % "Message: " Message
; REMOVE
; Message := PostTitle . "`n" . PostBody
; Msgbox % "TelegramTitle: " TelegramTitle
; Msgbox % "TelegramBody: " TelegramBody
; Msgbox % "Message: " Message
if(ImageAttachmentFilepath != "" AND StrLen(Message) > 1020){ ; utilize function that converts image to MIME/multi form
; Telegram API character limit of 4096 for a basic message.
; @todo: add functionality to split messages longer than 4096 characters
; msgbox, 2
if(BoldTitleWAPI)
TelegramTitle := "*" . TelegramTitle . "*"
else,
TelegramTitle := TelegramTitle
Status := SendTelegramPhoto(TelegramBotToken, TelegramBotChatID, ImageAttachmentFilepath, caption := TelegramTitle ) ; you could add more options; compare the Telegram API docs
Status := SendTelegramMessage(TelegramBotToken, TelegramBotChatID, text := TelegramBody )
}
else if(ImageAttachmentFilepath != "" AND StrLen(Message) <= 1020){
Status := SendTelegramPhoto(TelegramBotToken, TelegramBotChatID, ImageAttachmentFilepath, caption := Message ) ; you could add more options; compare the Telegram API docs
}
else,
{ ; send just the text
; Msgbox % "Message: " Message
Status := SendTelegramMessage(TelegramBotToken, TelegramBotChatID, text := Message )
}
if(Status){
Message = Upload Failed due to API issue. Telegram API Returned Value:`n %Status%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
; SaveOrPostProgress(Message:=Message,PostType:=",ErrorLoggingTextFile,DiscordParler")
IniWrite, Successful, %StatusFileFilePath%, Status, Telegram
AddToTotalPostsPostedCount()
Message = Submitted Successfully
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Return
; -------------------------------/Telegram-------------------------------
; -------------------------------LinkedIn------------------------------- ; -------------------------------LinkedIn-------------------------------

Loading…
Cancel
Save